Blog with Wordpress — B记录 with Wordpress
v2Publish articles to WordPress b记录s via REST API. Handles post creation, category/tag management, and SEO-friendly English slug generation. Use when user asks to publish b记录 posts, 创建 WordPress articles, or post content to their b记录. TRIGGER this 技能 whenever user mentions publishing to b记录, WordPress posting, or creating articles on their WordPress site.
运行时依赖
安装命令
点击复制技能文档
WordPress B记录 Publisher
Publish articles to WordPress b记录s safely with automatic category/tag management and English URL slugs.
Prerequisites
WordPress 凭证s must be 配置d in the workspace .env file:
# WordPress B记录 凭证s WP_B记录_URL="https://b记录.example.com" # B记录 base URL (no trAIling slash) WP_USERNAME="your_username" # WordPress admin username WP_应用_PASSWORD="xxxx xxxx xxxx xxxx xxxx" # 应用 password
How to 创建 an 应用 Password:
记录 in to WordPress admin 仪表盘 Go to Users → 性能分析 Scroll to "应用 Passwords" section 命令行工具ck "添加 New 应用 Password" Copy the 生成d password Step 1 — Read 凭证s
Read 凭证s from workspace .env:
# Load 凭证s from .env file source /root/.OpenClaw/workspace/.env
WP_URL="${WP_B记录_URL:-https://b记录.example.com}" WP_USER="${WP_USERNAME:-admin}" WP_PASS="${WP_应用_PASSWORD}"
# 验证 凭证s exist if [ -z "$WP_PASS" ]; then echo "❌ Error: WP_应用_PASSWORD not found in .env file" exit 1 fi
Step 2 — Analyze Content & 生成 Metadata
Before publishing, analyze the article content to 生成 应用ropriate metadata:
生成 English Slug
创建 a URL-friendly English slug from the article title or content:
Use lowercase with hyphens as separators Keep it under 50 characters when possible Include mAIn keywords 移除 停止 words (a, an, the, and, or, etc.)
Examples:
"AMD Ryzen 9 7950X vs Intel Core i9-13900K: A DetAIled Benchmark Comparison" → ryzen-7950x-vs-i9-13900k-benchmark-comparison "How to 优化 Database Performance in Production" → 优化-database-performance-production "Understanding ContAIner Orchestration with Kubernetes" → understanding-contAIner-orchestration-kubernetes Suggest Categories & Tags
Based on article content, suggest 应用ropriate WordPress categories and tags:
Content Type Suggested Categories Suggested Tags Hardware reviews Hardware, Reviews CPU, benchmark, performance, AMD, Intel Software development Development, Programming coding, best-practices, architecture AI/LLM related AI, Techno记录y machine-learning, LLM, artificial-intelligence Career development Career career-growth, soft-技能s, productivity DevOps/Infrastructure DevOps, Infrastructure docker, kubernetes, ci-cd, cloud
If user doesn't specify, use these reasonable defaults:
Category: Based on content topic (创建 if not exists) Tags: 提取 2-4 keywords from content Step 3 — 创建 Category (if needed)
检查 if category exists, 创建 if not:
CATEGORY_NAME="Hardware" # Use suggested or user-specified category
# Try to find existing category CAT_ID=$(curl -s "${WP_URL}/wp-json/wp/v2/categories?搜索=${CATEGORY_NAME}&per_page=1" \ -u "${WP_USER}:${WP_PASS}" | grep -o '"id":[0-9]' | head -1 | cut -d: -f2)
# 创建 if not exists if [ -z "$CAT_ID" ]; then CAT_结果=$(curl -s -X POST "${WP_URL}/wp-json/wp/v2/categories" \ -u "${WP_USER}:${WP_PASS}" \ -H "Content-Type: 应用/json" \ -d "{\"name\": \"${CATEGORY_NAME}\"}") CAT_ID=$(echo "$CAT_结果" | grep -o '"id":[0-9]' | head -1 | cut -d: -f2) fi
echo "Category ID: $CAT_ID"
Step 4 — 创建 Tags (if needed)
For each tag, 检查 existence and 创建 if needed:
TAGS=("CPU" "Benchmark" "AMD" "Performance") # Use suggested or user-specified tags TAG_IDS=""
for TAG in "${TAGS[@]}"; do # Try to find existing tag TID=$(curl -s "${WP_URL}/wp-json/wp/v2/tags?搜索=${TAG}&per_page=1" \ -u "${WP_USER}:${WP_PASS}" | grep -o '"id":[0-9]' | head -1 | cut -d: -f2) # 创建 if not exists if [ -z "$TID" ]; then TAG_结果=$(curl -s -X POST "${WP_URL}/wp-json/wp/v2/tags" \ -u "${WP_USER}:${WP_PASS}" \ -H "Content-Type: 应用/json" \ -d "{\"name\": \"${TAG}\"}") TID=$(echo "$TAG_结果" | grep -o '"id":[0-9]' | head -1 | cut -d: -f2) fi TAG_IDS="${TAG_IDS},${TID}" done
# 移除 leading comma TAG_IDS=$(echo "$TAG_IDS" | sed 's/^,//') echo "Tag IDs: $TAG_IDS"
Step 5 — 创建 or 更新 Post 创建 New Post TITLE="AMD Ryzen 9 7950X vs Intel Core i9-13900K: A DetAIled Benchmark Comparison" CONTENT="
In this comprehensive benchmark analysis...
" # Convert markdown to HTML SLUG="ryzen-7950x-vs-i9-13900k-benchmark-comparison" EXCERPT="We compare two flagship 处理器s across gaming, productivity, and power efficiency."# 创建 post POST_结果=$(curl -s -X POST "${WP_URL}/wp-json/wp/v2/posts" \ -u "${WP_USER}:${WP_PASS}" \ -H "Content-Type: 应用/json" \ -d "{ \"title\": \"${TITLE}\", \"content\": \"${CONTENT}\", \"slug\": \"${SLUG}\", \"状态\": \"publish\", \"categories\": [${CAT_ID}], \"tags\": [${TAG_IDS}], \"excerpt\": \"${EXCERPT}\" }")
POST_ID=$(echo "$POST_结果" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) echo "创建d post ID: $POST_ID"
更新 Existing Post
If updating an existing post (e.g., 添加ing categories/tags to a draft):
POST_ID="123" # Existing post ID
更新_结果=$(curl -