【问题标题】:Archive for Custom post type categories [closed]自定义帖子类型类别的存档[关闭]
【发布时间】:2015-01-10 00:46:16
【问题描述】:

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

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

www.website.com/news/ - 存档正在运行

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

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    是的,您可以通过将 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

    【讨论】:

      【解决方案2】:

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

      例如

      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)-> 您的分类名称(如类别)> 将鼠标悬停在每个标题上并点击查看来检查您的自定义分类 slug 的实际网址,

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

      如果您仍然收到错误页面,那么您注册该自定义类别的方式有问题

      【讨论】:

      • 代码和你上面提到的一样。我尝试了不同的自定义 slug 但没有用。我再次尝试保存永久链接。 :(。
      • 您能否提供一个自定义类别的默认链接?
      • 我刚刚注意到,你有一个默认的帖子类别新闻?并且您的基于自定义类别的网址也是新闻?对我来说看起来像 slug 冲突,你测试过默认永久链接吗?
      • 我将自定义类别 slug 更改为新闻类别
      • 测试默认永久链接,如yoursite.com/?news-category=political
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多