网淘吧来吧,欢迎您!

WordPress Publisher Skill技能使用说明

2026-03-29 新闻来源:网淘吧 围观:17
电脑广告
手机广告

WordPress发布器

使用REST API直接将内容发布到WordPress站点,支持完整的古腾堡区块格式化、自动分类选择、SEO标签生成和预览功能。

完整工作流程概述

1. CONNECT    → Authenticate with WordPress site
2. ANALYZE    → Load categories from site, analyze content for best match
3. GENERATE   → Create SEO-optimized tags based on content
4. CONVERT    → Transform markdown/HTML to Gutenberg blocks
5. PREVIEW    → Create draft and verify rendering
6. PUBLISH    → Publish or schedule the post
7. VERIFY     → Confirm live post renders correctly

步骤1:连接设置

获取凭证

向用户请求:

  • WordPress站点URL(例如,https://example.com
  • WordPress用户名
  • 应用程序密码(非普通密码)

如何创建应用程序密码

引导用户:

  1. 进入WordPress管理后台的用户 → 个人资料页面
  2. 滚动到应用程序密码部分
  3. 输入名称:Claude发布器
  4. 点击添加新应用密码
  5. 复制生成的密码(仅显示一次,带空格)

测试连接

from scripts.wp_publisher import WordPressPublisher

wp = WordPressPublisher(
    site_url="https://example.com",
    username="admin",
    password="xxxx xxxx xxxx xxxx xxxx xxxx"  # Application password
)

# Test connection
user_info = wp.test_connection()
print(f"Connected as: {user_info['name']}")

步骤2:加载并选择分类

从网站自动加载分类

# Get all categories from the WordPress site
categories = wp.get_categories_with_details()

# Returns list like:
# [
#   {'id': 1, 'name': 'Uncategorized', 'slug': 'uncategorized', 'count': 5},
#   {'id': 2, 'name': 'Tutorials', 'slug': 'tutorials', 'count': 12},
#   {'id': 3, 'name': 'Cloud Hosting', 'slug': 'cloud-hosting', 'count': 8},
# ]

智能分类选择

系统分析内容并选择最合适的分类:

# Analyze content and suggest best category
suggested_category = wp.suggest_category(
    content=article_content,
    title=article_title,
    available_categories=categories
)

# Or let user choose from available options
print("Available categories:")
for cat in categories:
    print(f"  [{cat['id']}] {cat['name']} ({cat['count']} posts)")

分类选择逻辑

  1. 精确匹配- 标题/内容包含分类名称
  2. 关键词匹配- 分类别名与主题关键词匹配
  3. 父级分类- 若无匹配则回退至更宽泛的父级分类
  4. 新建分类- 若无合适分类则新建(需用户批准)

步骤3:生成SEO优化标签

自动标签生成

生成提升谷歌搜索可见度的标签:

# Generate tags based on content analysis
tags = wp.generate_seo_tags(
    content=article_content,
    title=article_title,
    max_tags=10
)

# Returns list like:
# ['n8n hosting', 'workflow automation', 'self-hosted n8n', 
#  'affordable hosting', 'docker deployment', 'node.js hosting']

标签生成规则

  1. 主要关键词- 始终作为第一个标签包含
  2. 次要关键词- 包含2-3个相关术语
  3. 长尾关键词- 包含3-4个特定短语
  4. 实体标签- 包含提及的产品/品牌名称
  5. 主题标签- 包含更广泛的类别术语

在WordPress中创建/获取标签

# Get or create all tags, returns list of tag IDs
tag_ids = wp.get_or_create_tags(tags)

步骤4:将内容转换为古腾堡区块

Markdown 转 Gutenberg

from scripts.content_to_gutenberg import convert_to_gutenberg

# Convert markdown content
gutenberg_content = convert_to_gutenberg(markdown_content)

支持的转换

Markdown古腾堡区块
# 标题wp:heading
**加粗**<strong>在段落中
- 列表项wp:list
1. 有序wp:list {"ordered":true}
``代码````wp:code> 引用
wp:quote![替代文本](url)
wp:image| 表格 |
wp:table表格转换(对AI内容至关重要)

表格使用适当的Gutenberg结构进行转换:

步骤5:发布前预览

# Input markdown:
| Feature | Plan A | Plan B |
|---------|--------|--------|
| Price   | $10    | $20    |

# Output Gutenberg:
<!-- wp:table -->
<figure class="wp-block-table"><table>
  <thead><tr><th>Feature</th><th>Plan A</th><th>Plan B</th></tr></thead>
  <tbody><tr><td>Price</td><td>$10</td><td>$20</td></tr></tbody>
</table></figure>
<!-- /wp:table -->

创建预览草稿

验证预览

# Create as draft first
result = wp.create_draft(
    title="Article Title",
    content=gutenberg_content,
    categories=[category_id],
    tags=tag_ids,
    excerpt="Auto-generated or custom excerpt"
)

post_id = result['post_id']
preview_url = result['preview_url']
edit_url = result['edit_url']

预览检查清单

# Fetch preview page to verify rendering
preview_content = wp.fetch_preview(post_id)

# Check for issues
issues = wp.validate_rendered_content(preview_content)
if issues:
    print("Issues found:")
    for issue in issues:
        print(f"  - {issue}")

标题显示正确

  • 所有标题渲染正常(H2、H3、H4)
  • 表格渲染格式正确
  • 列表显示正确(项目符号和编号)
  • 代码块具有语法高亮
  • 图片加载正常(如果有)
  • 链接可点击
  • 分类显示正确
  • Category shows correctly
  • 文章中的标签显示

第六步:发布文章

发布草稿

# After preview approval, publish
result = wp.publish_post(post_id)
live_url = result['live_url']

或直接创建并发布

# Full publish workflow in one call
result = wp.publish_content(
    title="Article Title",
    content=gutenberg_content,
    category_names=["Cloud Hosting"],  # By name, auto-resolves to ID
    tag_names=["n8n", "hosting", "automation"],
    status="publish",  # or "draft", "pending", "private", "future"
    excerpt="Custom excerpt for SEO",
    slug="custom-url-slug"
)

定时发布文章

# Schedule for future publication
from datetime import datetime, timedelta

publish_date = datetime.now() + timedelta(days=1)
result = wp.publish_content(
    title="Scheduled Post",
    content=content,
    status="future",
    date=publish_date.isoformat()
)

第七步:验证已发布文章

检查线上文章

# Verify the published post
verification = wp.verify_published_post(post_id)

print(f"Live URL: {verification['url']}")
print(f"Status: {verification['status']}")
print(f"Categories: {verification['categories']}")
print(f"Tags: {verification['tags']}")

常见问题及解决方法

问题原因解决方案
表格无法渲染缺少图像包装器使用正确的wp:table区块结构
代码未高亮显示缺少语言属性添加{"language":"python"}到代码块
图片无法显示URL错误或缺少媒体文件先上传至WordPress,使用媒体ID
标签未显示主题不显示标签检查主题设置或使用不同主题

完整示例工作流

from scripts.wp_publisher import WordPressPublisher
from scripts.content_to_gutenberg import convert_to_gutenberg

# 1. Connect
wp = WordPressPublisher(
    site_url="https://xcloud.host",
    username="admin",
    password="xxxx xxxx xxxx xxxx"
)

# 2. Load categories and select best match
categories = wp.get_categories_with_details()
best_category = wp.suggest_category(content, title, categories)

# 3. Generate SEO tags
tags = wp.generate_seo_tags(content, title, max_tags=10)

# 4. Convert to Gutenberg
gutenberg_content = convert_to_gutenberg(markdown_content)

# 5. Create draft and preview
draft = wp.create_draft(
    title="7 Best n8n Hosting Providers in 2026",
    content=gutenberg_content,
    categories=[best_category['id']],
    tags=wp.get_or_create_tags(tags)
)
print(f"Preview: {draft['preview_url']}")

# 6. After verification, publish
result = wp.publish_post(draft['post_id'])
print(f"Published: {result['live_url']}")

快速参考

API端点

资源端点
文章/wp-json/wp/v2/posts
页面/wp-json/wp/v2/pages
分类/wp-json/wp/v2/categories
标签/wp-json/wp/v2/tags
媒体/wp-json/wp/v2/media

文章状态

状态描述
发布已上线且可见
草稿已保存但不可见
待处理等待审核
私有仅管理员可见
未来计划稍后发布

必需文件

  • scripts/wp_publisher.py- 主发布类
  • scripts/content_to_gutenberg.py- Markdown/HTML 转换器
  • references/gutenberg-blocks.md- 区块格式参考

错误处理

错误代码含义解决方案
401凭据无效检查用户名和应用程序密码
403权限不足用户需要编辑者或管理员角色
404端点未找到验证REST API是否启用
400数据无效检查分类/标签ID是否存在
500服务器错误重试或检查WordPress错误日志

最佳实践

  1. 始终先预览- 创建为草稿,验证后再发布
  2. 使用应用程序密码- 切勿使用常规WordPress密码
  3. 选择适当的分类- 有助于网站组织和SEO
  4. 生成相关标签- 提高谷歌可发现性
  5. 验证Gutenberg区块- 确保区块结构正确
  6. 保持摘要不超过160个字符- 最佳搜索摘要长度
  7. 使用描述性别名- 在URL中包含主要关键词
免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326263名访客 今日有221篇新文章/评论