分类模板页面不起作用

时间:2017-11-14 作者:HeroWeb512

我有一个名为doctor services的分类法注册,还有一个名为taxonomy doctor services的分类法模板。php,但当我单击分类法链接时,它不会显示分类法的详细信息。这是一个代码

  function doctors_custom_post(){
    $labels = array(
        \'name\' => \'Doctors\',
        \'singular_name\' => \'Doctor\',
        \'add_new\' => \'Add Doctor\',
        \'add_new_item\' => \'Add New Doctor\',
        \'all_items\' => \'All Doctors\',
        \'edit_item\' => \'Edit Item\',
        \'new_item\' => \'New Item\',
        \'view_item\' => \'View Item\',
        \'search_items\' => \'Search Doctors\',
        \'not_found\' => \'No record found\',
        \'not_found_in_trash\' => \'No items found in trash\',
        \'parent_item_colon\' => \'Parent Item\'
        );
        $args = array(
            \'labels\' => $labels,
            \'public\' => true,
            \'publicly_queryable\' => true,
            \'show_ui\' => true,
            \'query_var\' => true,
            \'rewrite\' => true,
            \'capability_type\' => \'post\',
            \'hierarchical\' => false,
            \'supports\' => array(\'title\', \'editor\', \'excerpt\', \'thumbnail\', \'revisions\'),
            //\'taxonomies\' => array(\'category\', \'post_tags\'),
            \'menu_position\' => 15,
            \'exclude_from_search\' => false
            );
            register_post_type(\'my-doctor\', $args);     
}
add_action(\'init\', \'doctors_custom_post\');
add_action( \'init\', \'doctors_my_taxonomy\');
function doctors_my_taxonomy(){
// custom post type taxonomies
        $labels = array(
        \'name\' => \'Doctor Departments\',
        \'singular_name\' => \'Doctor Department\',
        \'add_new\' => \'Add Department\',
        \'add_new_item\' => \'Add New Department\',
        \'all_items\' => \'All Departments\',
        \'edit_item\' => \'Edit Item\',
        \'new_item\' => \'New Item\',
        \'view_item\' => \'View Item\',
        \'update_item\' => \'Update Department\',
        \'search_items\' => \'Search Departments\',
        \'not_found\' => \'No record found\',
        \'not_found_in_trash\' => \'No items found in trash\',
        \'parent_item_colon\' => \'Parent Item\',
        \'menu_name\' => \'Departments\'
        );
        $args = array(
            \'labels\' => $labels,
            \'hierarchical\' => true,
            \'has_archive\' => true,
            \'rewrite\' => array(\'slug\' => \'doctor_departments\'),
            \'show_ui\' => true,
            \'show_admin_column\' => true,
            \'query_var\' => true,
            );
            register_taxonomy(\'doctor-department\', array(\'my-doctor\'), $args);
    $labels = array(
        \'name\' => \'Diseases\',
        \'singular_name\' => \'Diseases\',
        \'add_new\' => \'Add Disease\',
        \'add_new_item\' => \'Add New Disease\',
        \'all_items\' => \'All Disease\',
        \'edit_item\' => \'Edit Item\',
        \'new_item\' => \'New Item\',
        \'view_item\' => \'View Item\',
        \'update_item\' => \'Update Disease\',
        \'search_items\' => \'Search Disease\',
        \'not_found\' => \'No record found\',
        \'not_found_in_trash\' => \'No items found in trash\',
        \'parent_item_colon\' => \'Parent Item\',
        \'menu_name\' => \'Diseases\'
        );
        $args = array(
            \'labels\' => $labels,
            \'hierarchical\' => true,
            \'has_archive\' => true,
            \'rewrite\' => array(\'slug\' => \'doctor_diseases\'),
            \'show_ui\' => true,
            \'show_admin_column\' => true,
            \'query_var\' => true,
            );
            register_taxonomy(\'doctor-diseases\', array(\'my-doctor\'), $args);
    $labels = array(
        \'name\' => \'Services\',
        \'singular_name\' => \'Service\',
        \'add_new\' => \'Add Service\',
        \'add_new_item\' => \'Add New Service\',
        \'all_items\' => \'All Services\',
        \'edit_item\' => \'Edit Item\',
        \'new_item\' => \'New Item\',
        \'view_item\' => \'View Item\',
        \'update_item\' => \'Update Service\',
        \'search_items\' => \'Search Service\',
        \'not_found\' => \'No record found\',
        \'not_found_in_trash\' => \'No items found in trash\',
        \'parent_item_colon\' => \'Parent Item\',
        \'menu_name\' => \'Services\'
        );
        $args = array(
            \'labels\' => $labels,
            \'public\' => true,
            \'publicly_queryable\' => true,
            \'hierarchical\' => true,
            \'has_archive\' => true,
            \'rewrite\' => array(\'slug\' => \'doctor_services\'),
            \'show_ui\' => true,
            \'show_admin_column\' => true,
            \'query_var\' => true,
            );
            register_taxonomy(\'doctor-services\', array(\'my-doctor\'), $args);
}
和分类服务页面

      <?php
      get_header(); ?>
      <div id="primary">
      <div id="content" class="content">
      <div class="container">
      <div class="row">
    <div class="col-sm-12 col-md-9 col-lg-9">
       <h2> <?php 
        single_cat_title();
        ?>
        </h2>
        <?php category_description(); ?>
       </div>
        </div>
        </div>
          </div>
          </div>
        <?php get_footer(); ?>
和分类链接

http://example.com/doctor_services/xray/

请帮助错误在哪里

1 个回复
最合适的回答,由SO网友:DHL17 整理而成

使用the_archive_title(); 而不是single_cat_title();the_archive_description(); 而不是category_description();

将此代码添加到functions.php

add_filter(\'get_the_archive_title\', function ($title) {
    return preg_replace(\'/^\\w+: /\', \'\', $title);
});

结束

相关推荐

Taxonomy Page Go to 404 pgae

我正在使用Redux框架创建一个自定义帖子类型。创建一个类别和该类别视图直接和直接转到链接,但该链接应直接转到404页。请检查下面的代码,让我知道我的代码中有什么错误。remove_action( \'init\', \'brightness_service_register\',10 ); add_action( \'init\', \'brightness_service_register\',1 ); function brightness_service_register()