【问题标题】:Single Taxonomy page template not working单一分类页面模板不起作用
【发布时间】:2017-07-13 18:30:56
【问题描述】:

我正在尝试在我的 wordpress 主题中创建自定义分类页面模板,但它始终显示 archive.php 尽管我创建了 taxonomy-lesson_categories.php 并且也尝试过taxonomy-lesson-category.php 但不是那种工作。

这是我在functions.php中的分类函数:

function cv_themes_taxonomy() {  
    register_taxonomy(  
        'lesson_categories',  //The name of the taxonomy.  
        'cv',        //post type name
        array(  
            'hierarchical' => true,  
            'label' => 'Lesson Category',  //Display name
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'lesson-category', 
                'with_front' => true 
            )
        )  
    );  
}  

add_action( 'init', 'cv_themes_taxonomy');

注意:我的 post_type 名称是 CV

有人知道原因吗?

【问题讨论】:

    标签: php wordpress custom-post-type taxonomy custom-taxonomy


    【解决方案1】:

    您需要阅读 WordPress.org 上的 https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/ 分类模板文章以了解该信息。

    【讨论】:

      【解决方案2】:

      //我在我的functions.php文件中使用了以下代码,并在管理员中再次保存了永久链接以生效。是的,它工作正常。我试过了。:-

      function cv_themes_taxonomy() {  
          register_taxonomy(  
              'lesson_categories',  //The name of the taxonomy.  
              'cv',        //post type name
              array(  
                  'hierarchical' => true,  
                  'label' => 'Lesson Category',  //Display name
                  'query_var' => true,
                  'rewrite' => array(
                      'slug' => 'lesson-category', 
                      'with_front' => true 
                  )
              )  
          );  
      }  
      
      add_action( 'init', 'cv_themes_taxonomy');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-02
        • 1970-01-01
        • 2018-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-14
        • 1970-01-01
        相关资源
        最近更新 更多