资源分类中心

探索我们精心整理的各类资源,助力你的学习与成长

0
资源总数
0
主分类
0
子分类

所有资源

浏览所有分类的资源内容

加载资源中...

WordPress API 设置指南

1 安装必要插件

安装以下WordPress插件:

  • Custom Post Type UI - 创建自定义文章类型
  • Advanced Custom Fields - 添加自定义字段
  • ACF to REST API - 在API中公开ACF字段

2 创建资源文章类型

使用CPT UI创建名为"Resource"的自定义文章类型:

// functions.php function create_resource_post_type() { register_post_type('resource', array( 'labels' => array( 'name' => __('Resources'), 'singular_name' => __('Resource') ), 'public' => true, 'has_archive' => true, 'show_in_rest' => true, 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'), ) ); } add_action('init', 'create_resource_post_type');

3 创建自定义分类法

创建主分类和子分类:

// functions.php function create_resource_taxonomies() { // 主分类 register_taxonomy( 'resource_category', 'resource', array( 'label' => __('Resource Categories'), 'hierarchical' => true, 'show_in_rest' => true ) ); // 子分类 register_taxonomy( 'resource_sub_category', 'resource', array( 'label' => __('Resource Sub Categories'), 'hierarchical' => true, 'show_in_rest' => true ) ); } add_action('init', 'create_resource_taxonomies');

4 添加自定义字段

使用ACF添加以下字段:

  • icon - Font Awesome图标类名
  • color - 卡片背景色
  • link - 资源链接
  • tags - 标签列表

5 注册自定义API端点

// functions.php add_action('rest_api_init', function() { // 分类端点 register_rest_route('navagpt/v1', '/categories', array( 'methods' => 'GET', 'callback' => 'get_resource_categories', )); // 资源端点 register_rest_route('navagpt/v1', '/resources', array( 'methods' => 'GET', 'callback' => 'get_resources', )); // 统计端点 register_rest_route('navagpt/v1', '/stats', array( 'methods' => 'GET', 'callback' => 'get_resource_stats', )); });
API状态: 正在检查...