自定义存档后页面不起作用

时间:2022-02-19 作者:Lokesh8285
add_action(\'init\', function() {
    register_post_type(\'vendorpost\', [
        \'label\' => __(\'Vendor Post\', \'txtdomain\'),
        \'public\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => \'dashicons-admin-users\',
        \'supports\' => [\'title\', \'editor\', \'thumbnail\', \'tag\', \'revisions\', \'comments\'],
        \'show_in_rest\' => true,
        \'rewrite\' => [\'slug\' => \'vendorposts\'],
        \'taxonomies\' => [\'vendorpost_author\', \'vendorpost_genre\'],
        \'labels\' => [
            \'singular_name\' => __(\'Vendor Post\', \'txtdomain\'),
            \'add_new_item\' => __(\'Add new vendor post\', \'txtdomain\'),
            \'new_item\' => __(\'New Vendor Post\', \'txtdomain\'),
            \'view_item\' => __(\'View Vendor Post\', \'txtdomain\'),
            \'not_found\' => __(\'No Vendor Post found\', \'txtdomain\'),
            \'not_found_in_trash\' => __(\'No Vendor Post found in trash\', \'txtdomain\'),
            \'all_items\' => __(\'All Vendor Post\', \'txtdomain\'),
            \'insert_into_item\' => __(\'Insert into Vendor Post\', \'txtdomain\')
        ],      
    ]);
 
    register_taxonomy(\'vendorpost_category\', [\'vendorpost\'], [
        \'label\' => __(\'Categories\', \'txtdomain\'),
        \'hierarchical\' => true,
        \'rewrite\' => [\'slug\' => \'vendorposts-category\'],
        \'show_admin_column\' => true,
        \'show_in_rest\' => true,
        \'labels\' => [
            \'singular_name\' => __(\'Category\', \'txtdomain\'),
            \'all_items\' => __(\'All Category\', \'txtdomain\'),
            \'edit_item\' => __(\'Edit Category\', \'txtdomain\'),
            \'view_item\' => __(\'View Category\', \'txtdomain\'),
            \'update_item\' => __(\'Update Category\', \'txtdomain\'),
            \'add_new_item\' => __(\'Add New Category\', \'txtdomain\'),
            \'new_item_name\' => __(\'New Category Name\', \'txtdomain\'),
            \'search_items\' => __(\'Search Categorys\', \'txtdomain\'),
            \'parent_item\' => __(\'Parent Category\', \'txtdomain\'),
            \'parent_item_colon\' => __(\'Parent Category:\', \'txtdomain\'),
            \'not_found\' => __(\'No Category found\', \'txtdomain\'),
        ]
    ]);
    register_taxonomy_for_object_type(\'vendorpost_category\', \'vendorpost\');
 
    register_taxonomy(\'vendorpost_tag\', [\'vendorpost\'], [
        \'label\' => __(\'Tags\', \'txtdomain\'),
        \'hierarchical\' => false,
        \'rewrite\' => [\'slug\' => \'vendorposts-tag\'],
        \'show_admin_column\' => true,
        \'labels\' => [
            \'singular_name\' => __(\'Tag\', \'txtdomain\'),
            \'all_items\' => __(\'All Tags\', \'txtdomain\'),
            \'edit_item\' => __(\'Edit Tag\', \'txtdomain\'),
            \'view_item\' => __(\'View Tag\', \'txtdomain\'),
            \'update_item\' => __(\'Update Tag\', \'txtdomain\'),
            \'add_new_item\' => __(\'Add New Tag\', \'txtdomain\'),
            \'new_item_name\' => __(\'New Tag Name\', \'txtdomain\'),
            \'search_items\' => __(\'Search Tags\', \'txtdomain\'),
            \'popular_items\' => __(\'Popular Tags\', \'txtdomain\'),
            \'separate_items_with_commas\' => __(\'Separate Tags with comma\', \'txtdomain\'),
            \'choose_from_most_used\' => __(\'Choose from most used Tags\', \'txtdomain\'),
            \'not_found\' => __(\'No Tags found\', \'txtdomain\'),
        ]
    ]);
    register_taxonomy_for_object_type(\'vendorpost_tag\', \'vendorpost\');
});
1 个回复
SO网友:rudtek

如果您想查看自定义帖子的存档,存档将是:

archive-vendorpost.php

切换到类别时,wordpress会使用一个单独的模板:

taxonomy-vendorpost_category.php

还请记住,您需要访问permalinks页面以在之后重置它们,因为您的代码不能为您这样做。

我已经在我的系统上测试了你的代码,一切正常。

相关推荐

shortcode // get posts by ids

我正在寻找一个解决方案,以显示在一个快捷码自定义职位。对于一篇文章来说,这已经按预期工作了,但是我想指定多个ID。比如:[posts id=1、2、3、4]因为我来自前端领域,我缺乏相应地调整功能的方法,希望这里有人能为我提供解决方案。add_shortcode( \'posts\', \'posts_shortcode\' ); function posts_shortcode($atts) { $atts = shortcode_atts( array(&#x