-- 创造无限可能

wordpress开发:添加自定义文章类型

2022-08-01 11:38:51
556 人浏览 0 人点赞
有用,点赞支持一下

场景

wordpress默认只有一种文章类型,有时候需要添加自定义的文章类型:比如演员、电影、公告等

相关钩子

  • register_post_type

    代码演示

    /**
    * @return void 公告
    */
    function my_custom_post_announcement()
    {
      $labels = array(
              'name' => _x('公告', '公告'),
              'singular_name' => _x('announcement', 'announcement'),
              'add_new' => _x('add', 'add'),
              'add_new_item' => __('add'),
              'edit_item' => __('edit'),
              'new_item' => __('add'),
              'all_items' => __('All items'),
              'view_item' => __('View'),
              'search_items' => __('Search'),
              'not_found' => __('not Found'),
              'not_found_in_trash' => __('not found in trash'),
              'parent_item_colon' => '',
              'menu_name' => '公告'
      );
      $args = array(
              'labels' => $labels,
              'description' => '',
              'public' => true,
              'menu_position' => 5,
              'supports' => array('title', 'editor', 'thumbnail'),
              'has_archive' => true
      );
      register_post_type('announcement', $args);
    }