百度SEO

百度SEO

Products

当前位置:首页 > 百度SEO >

学习如何给自定义文章类型添加分类,轻松管理文章类别!

96SEO 2025-11-17 10:54 0


在WordPress中, 自定义文章类型是一种强大的功Neng,它允许我们创建与常规文章不同的内容类型。只是默认情况下自定义文章类型并不包含分类功Neng。本文将指导你如何为自定义文章类型添加分类,并轻松管理文章类别,准确地说...。

准备工作

在开始之前,请确保你Yi经:

如何给自定义文章类型(CPT)里面添加分类(Categories)?
  1. 熟悉WordPress的基础操作。
  2. 了解自定义文章类型的概念和注册方法。
  3. 熟悉Taxonomy的基本知识。

注册自定义文章类型

先说说我们需要注册一个自定义文章类型。 php function register_my_custom_post_type { $labels = array( 'name' => _x, 'singular_name' => _x, 'menu_name' => __, 'name_admin_bar' => __, 'archives' => __, 'attributes' => __, 'parent_item_colon' => __, 'all_items' => __, 'add_new_item' => __, 'add_new' => __, 'new_item' => __, 'edit_item' => __, 'update_item' => __, 'view_item' => __, 'view_items' => __, 'search_items' => __, 'not_found' => __, 'not_found_in_trash' => __, 'featured_image' => __, 'set_featured_image' => __, 'remove_featured_image' => __, 'use_featured_image' => __, 'insert_into_item' => __, 'uploaded_to_this_item' => __, 'items_list' => __, 'items_list_navigation' => __, 'filter_items_list' => __, ); $args = array( 'label' => __, 'description' => __, 'labels' => $labels, 'supports' => array, 'taxonomies' => array, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type; } add_action; 添加自定义分类 操作一波... 接下来我们需要为自定义文章类型添加分类。 得了吧... php function register_my_custom_taxonomy { $labels = array( 'name' => _x, 'singular_name' => _x, 'menu_name' => __, 'all_items' => __, 'parent_item' => __, 'parent_item_colon' => __, 'new_item_name' => __, 'add_new_item' => __, 'add_new' => __, 'new_item' => __, 'edit_item' => __, 'update_item' => __, 'view_item' => __, 'separate_items_with_commas' => __, 'add_or_remove_items' => __, 'choose_from_most_used' => __, 'popular_items' => __, 'search_items' => __, 'not_found' => __, 'no_terms' => __, 'items_list' => __, 'items_list_navigation' => __, ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy, $args ); } add_action; 测试自定义分类 在添加自定义分类后你Ke以: 登录WordPress后台。 点击“分类”菜单。 你应该会kan到一个新的分类列表,包括“分类”和“Press Category”。 通过以上步骤, 你Ke以在WordPress中为自定义文章类型添加分类,并轻松管理文章类别。希望本文对你有所帮助!



提交需求或反馈

Demand feedback