登录
0
0
0
0
举报

wordpress分类法新建一个文档

要在WordPress中新建一个分类法(taxonomy),你可以按照以下步骤操作:

1.使用代码编辑器或插件:

2.如果你熟悉使用代码编辑器(如VS Code、Sublime Text等),可以通过编辑主题的functions.php文件或创建一个自定义插件来添加新的分类法。

3.编辑functions.php文件(如果你选择这种方法):

4.首先,登录你的WordPress后台,转到 外观 -> 编辑器。

5.找到并点击编辑 functions.php 文件(请务必在修改前备份文件)。

6.在文件的末尾添加以下代码来创建一个新的分类法:

   // Register Custom Taxonomy
   function custom_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Taxonomies', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Taxonomy', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Taxonomy', 'text_domain' ),
        'all_items'                  => __( 'All Items', 'text_domain' ),
        'parent_item'                => __( 'Parent Item', 'text_domain' ),
        'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
        'new_item_name'              => __( 'New Item Name', 'text_domain' ),
        'add_new_item'               => __( 'Add New Item', 'text_domain' ),
        'edit_item'                  => __( 'Edit Item', 'text_domain' ),
        'update_item'                => __( 'Update Item', 'text_domain' ),
        'view_item'                  => __( 'View Item', 'text_domain' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
        'popular_items'              => __( 'Popular Items', 'text_domain' ),
        'search_items'               => __( 'Search Items', 'text_domain' ),
        'not_found'                  => __( 'Not Found', 'text_domain' ),
        'no_terms'                   => __( 'No items', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'taxonomy', array( 'post' ), $args );

    }
    add_action( 'init', 'custom_taxonomy', 0 );

7.修改代码:

8.将 taxonomy 替换为你想要的分类法名称,如 genre、topic等。

9.自定义标签中的文字(如 'Taxonomy'、'All Items'等)可以根据你的需要进行修改。

10.保存文件

11.在编辑器中保存 functions.php 文件。

12.检查和使用:

13.回到WordPress后台,刷新你的网站页面。

14.转到 文章 -> 分类法 查看你的新分类法是否已成功添加。

15.在撰写或编辑文章时,你应该能够为文章选择新的分类法。

如果你不熟悉代码编辑,也可以考虑使用WordPress插件来创建自定义分类法,如 Custom Post Type UI 或 Pods - Custom Content Types and Fields 等。

通过这些步骤,你就可以在WordPress中成功创建并使用自定义的分类法了。

本文经过AI辅助创作,作者不保证其准确性和可靠性。任何人因采取本文所述观点、做出决策或实施行动,所造成的损失,本网站概不负责。
2月前更新
您的位置:教程学习
发布于:2024/07/01 13:04:07
评论0条
发布