归档自定义帖子类型类别

时间:2015-01-10 00:46:17

标签: php wordpress custom-post-type

我创建了自定义帖子类型并为自定义帖子类型创建了自定义类别。我能够显示每个自定义类别的帖子,但不能显示每个类别的存档。请帮助我获取每个自定义类别的存档

自定义帖子类型 - 新闻 类别 - 政治

www.website.com/news/ - 存档工作

www.website.com/news/political - 显示404错误。

2 个答案:

答案 0 :(得分:0)

注册自定义分类时,您是否有重写规则?

e.g。

register_taxonomy( 'taxonomy_name', 
    array('post_type_name'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
    array('hierarchical' => true,     /* if this is true, it acts like categories */             
        'labels' => array(
            //blah blah blah
        ),
        'show_admin_column' => true, 
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'custom-slug' ),
    )
); 

您可以尝试通过转到您的帖子类型名称(如POST)来检查自定义分类标本的实际网址 - >您的分类名称(如类别)>将鼠标悬停在每个标题上,然后点击查看

如果您仍然收到错误页面,请尝试将固定链接重置为默认值并再次检查

如果您仍然收到错误页面,则注册该自定义类别

的方法有问题

答案 1 :(得分:0)

是的,您可以通过将 has_archive 设置为 true 来添加档案。

$args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'book' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);

参考:http://codex.wordpress.org/Function_Reference/register_post_type

相关问题