自定义帖子类型类别页面/模板

时间:2017-01-02 19:18:14

标签: php wordpress custom-post-type

我创建了一个自定义帖子类型,其中包含一系列需要各自登录页面的不同类别。现在我已经通过了WP Post Type Templates,但我仍然无法显示类别页面。现在,CPT类别页面只有404。

我尝试过以下操作:

  1. 根据this注册帖子类型档案。
  2. 使用 archive-teams.php archive-team.php 创建归档模板文件。
  3. 尝试使用 category-teams.php category-team.php
  4. 刷新永久链接100万次。
  5. 以下是我如何注册帖子类型和分类:

    add_action('init', 'create_team');
    function create_team() {
    
      register_taxonomy(
        'teams',
        array(),
        array(
          'hierarchical' => true,
          'labels' => array
          (
            'name' => _x('Teams', 'taxonomy general name'),
            'singular_name' => _x('Team', 'taxonomy singular name')
          ),
          'show_ui' => true,
          'show_admin_column' => true,
          'query_var' => 'team',
          'rewrite' => array(
              'slug' => 'our-team',
          ),
        )
      );
    
      register_post_type(
        'team',
        array(
          'labels' => array
          (
            'name' => _x('Team Members', 'post type general name'),
            'singular_name' => _x('Team Member', 'post type singular name')
          ),
          'supports' => array('title', 'editor', 'thumbnail'),
          'public' => true,
          'rewrite' => array
          (
            'slug' => 'our-team/%teams%',
            'with_front' => false
          ),
          'query_var' => 'team',
          'has_archive' => 'team',
          'taxonomies' => array( 'teams','category','post_tag' ),
        )
      );
    }
    

1 个答案:

答案 0 :(得分:0)

您应该尝试使用archive- $ customposttype.php来编辑存档文件,包括自定义帖子类型的类别页面模板。您可以在此处阅读更多内容https://developer.wordpress.org/themes/basics/template-hierarchy/

相关问题