我正在尝试为自定义分类法设置自定义模板。当我单击一个类别链接以显示该特定类别中的自定义帖子时,我会看到404页面。我的自定义帖子类型文件名是模板功能。php和我的分类归档文件是归档特性。php。下面是我注册分类法和帖子类型的代码:
自定义帖子类型和分类:
add_action( \'init\', \'post_type_features\', 0 );
function post_type_features() {
$labels = array(
\'name\' => _x( \'Features\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Feature\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Features\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Feature:\', \'text_domain\' ),
\'all_items\' => __( \'All Features\', \'text_domain\' ),
\'view_item\' => __( \'View Feature\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Feature\', \'text_domain\' ),
\'add_new\' => __( \'Add New\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Feature\', \'text_domain\' ),
\'update_item\' => __( \'Update Feature\', \'text_domain\' ),
\'search_items\' => __( \'Search Features\', \'text_domain\' ),
\'not_found\' => __( \'Not found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'post_features\', \'text_domain\' ),
\'description\' => __( \'White Glove Labs Features\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'custom-fields\', ),
\'taxonomies\' => array( \'Features\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_icon\' => \'dashicons-star-empty\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
);
register_post_type( \'post_features\', $args );
}
add_action( \'init\', \'lv_features_taxonomy\', 0 );
function lv_features_taxonomy() {
$labels = array(
\'name\' => _x( \'Features\', \'Features Taxonomy\' ),
\'singular_name\' => _x( \'Feature\', \'Feature singular name\' ),
\'search_items\' => __( \'Search Features\' ),
\'all_items\' => __( \'All Features\' ),
\'parent_item\' => __( \'Parent Feature\' ),
\'parent_item_colon\' => __( \'Parent Feature:\' ),
\'edit_item\' => __( \'Edit Feature\' ),
\'update_item\' => __( \'Update Feature\' ),
\'add_new_item\' => __( \'Add New Feature\' ),
\'new_item_name\' => __( \'New Feature Name\' ),
\'menu_name\' => __( \'Features Categories\' ),
);
register_taxonomy(\'features\',array(\'post_features\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'features\' ),
));
}
只是为了测试,我有一个非常基本的自定义归档文件。代码如下:
<?php get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<header class="archive-header">
<h1 class="archive-title">
<?php post_type_archive_title(); ?>
</h1>
</header>
</div>
</div>
</div>
<?php
get_sidebar();
get_footer();