自定义帖子类型和类别(带有子类别)不起作用

时间:2018-10-03 10:11:46

标签: wordpress custom-post-type categories

我正在一个非我自己编程的网站上工作,我无法解决自定义帖子类型和类别的问题。

网站上的网址应为

www.my-site.com/shoes /

www.my-site.com/shoes/man-shoes /

www.my-site.com/shoes/man-shoes/sniker /

www.my-site.com/shoes/man-shoes/sniker/产品名称

应该可以从该站点访问所有页面。但是我有这个问题:

www.my-site.com/shoes/(无效,第404页)

www.my-site.com/shoes/man-shoes/(工作)

www.my-site.com/shoes/man-shoes/sniker/(工作)

www.my-site.com/shoes/man-shoes/sniker/产品名称(无效,第404页)

鞋子是CPT子弹

男鞋是CPT的主要类别

sniker是男鞋的子类别

用于创建自定义帖子类型和类别的代码为:

function register_shoes_post_type()
    {
        register_post_type('shoes', [
            'labels'        => [
              'name'                  => __('Shoes', PLUGIN_SLUG),
              'singular_name'         => __('Shoe', PLUGIN_SLUG),
              'add_new'               => __('Add New', PLUGIN_SLUG),
              'add_new_item'          => __('Add New Shoes', PLUGIN_SLUG),
              'edit_item'             => __('Edit Shoes', PLUGIN_SLUG),
              'new_item'              => __('New Shoes', PLUGIN_SLUG),
              'view_item'             => __('View Shoes', PLUGIN_SLUG),
              'view_items'            => __('View Shoes', PLUGIN_SLUG),
              'search_items'          => __('Search Shoes', PLUGIN_SLUG),
              'not_found'             => __('No Shoes found.', PLUGIN_SLUG),
              'not_found_in_trash'    => __('No Shoes found in Trash.', PLUGIN_SLUG),
              'parent_item_colon'     => __('Parent Shoes:', PLUGIN_SLUG),
              'all_items'             => __('All Shoes', PLUGIN_SLUG),
              'archives'              => __('Shoes Archives', PLUGIN_SLUG),
              'attributes'            => __('Shoes Attributes', PLUGIN_SLUG),
              'insert_into_item'      => __('Insert into Shoes', PLUGIN_SLUG),
              'uploaded_to_this_item' => __('Uploaded to this Shoes', PLUGIN_SLUG),
              'featured_image'        => __('Shoes picture', PLUGIN_SLUG),
              'set_featured_image'    => __('Set Shoes picture', PLUGIN_SLUG),
              'remove_featured_image' => __('Remove Shoes picture', PLUGIN_SLUG),
              'use_featured_image'    => __('Use as Shoes picture', PLUGIN_SLUG),
              'filter_items_list'     => __('Filter Shoes list', PLUGIN_SLUG),
              'items_list_navigation' => __('Shoes list navigation', PLUGIN_SLUG),
              'items_list'            => __('Shoes list', PLUGIN_SLUG)
            ],
            'public'        => TRUE,
            'has_archive'   => false,
            'menu_icon'     => 'dashicons-products',
            'rewrite'       => [
                'slug' => 'shoes',
                'with_front' => FALSE
            ],
            'supports'      => [
              'title',
              'editor',
              'thumbnail' 
            ]
          ]
        );
    }

用于创建自定义帖子stype类别的代码是

function registershoesCategoryTaxonomy()
{
    register_taxonomy(
        'shoes_category',
        'shoes',
        [
            'labels' => [
                'name' => __('Shoes category', PLUGIN_SLUG),
                'singular_name' => __('Shoes category', PLUGIN_SLUG),
                'menu_name' => __('Shoes category', PLUGIN_SLUG),
                'all_items' => __('All Shoes category', PLUGIN_SLUG),
                'parent_item' => __('Parent Shoes category', PLUGIN_SLUG),
                'parent_item_colon' => __('Parent Shoes category:', PLUGIN_SLUG),
                'new_item_name' => __('New Shoes category name', PLUGIN_SLUG),
                'add_new_item' => __('Add new Shoes category', PLUGIN_SLUG),
                'edit_item' => __('Edit Shoes category', PLUGIN_SLUG),
                'update_item' => __('Update Shoes category', PLUGIN_SLUG),
                'view_item' => __('View Shoes category', PLUGIN_SLUG),
                'separate_items_with_commas' => __('Separate Shoes category with commas', PLUGIN_SLUG),
                'add_or_remove_items' => __('Add or remove Shoes category', PLUGIN_SLUG),
                'choose_from_most_used' => __('Choose from the most used', PLUGIN_SLUG),
                'popular_items' => __('Popular Shoes category',     PLUGIN_SLUG),
                'search_items' => __('Search Shoes category', PLUGIN_SLUG),
                'not_found' => __('Not Found', PLUGIN_SLUG),
                'no_terms' => __('No Shoes category', PLUGIN_SLUG),
                'items_list' => __('Shoes category list', PLUGIN_SLUG),
                'items_list_navigation' => __('Shoes category list navigation', PLUGIN_SLUG)
            ],
            'hierarchical' => TRUE,
            'show_admin_column' => TRUE,
            'rewrite' => [
                'slug' => 'shoes',
                'hierarchical' => FALSE,
                'with_front' => FALSE
            ]
        ]
    );
}

我创建CPT不好,有人可以帮助我了解此问题吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

您应该尝试以下操作:

在自定义帖子类型中将has_archive设置为“ true”,然后检查www.my-site.com/shoes

'has_archive'   => true,
相关问题