我已经创建了custom post type 而且是taxonomies.代码为:
add_action( \'init\', \'register_cpt_portfolio\' );
function register_cpt_portfolio() {
$labels = array(
\'name\' => _x( \'portfolios\', \'portfolio\' ),
\'singular_name\' => _x( \'portfolio\', \'portfolio\' ),
\'add_new\' => _x( \'Add New portfolio\', \'portfolio\' ),
\'add_new_item\' => _x( \'Add New portfolio\', \'portfolio\' ),
\'edit_item\' => _x( \'Edit portfolio\', \'portfolio\' ),
\'new_item\' => _x( \'New portfolio\', \'portfolio\' ),
\'view_item\' => _x( \'View portfolio\', \'portfolio\' ),
\'search_items\' => _x( \'Search portfolios\', \'portfolio\' ),
\'not_found\' => _x( \'No portfolios found\', \'portfolio\' ),
\'not_found_in_trash\' => _x( \'No portfolios found in Trash\', \'portfolio\' ),
\'parent_item_colon\' => _x( \'Parent portfolio:\', \'portfolio\' ),
\'menu_name\' => _x( \'portfolios\', \'portfolio\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'Test Portfolio Posts\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'custom-fields\', \'page-attributes\' ),
\'taxonomies\' => array( \'category\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 2,
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'page\'
);
register_post_type( \'portfolio\', $args );
}
add_action( \'init\', \'register_taxonomy_portfolio_taxonomies\' );
function register_taxonomy_portfolio_taxonomies() {
$labels = array(
\'name\' => _x( \'portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'singular_name\' => _x( \'portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'search_items\' => _x( \'Search portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'popular_items\' => _x( \'Popular portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'all_items\' => _x( \'All portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'parent_item\' => _x( \'Parent portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'parent_item_colon\' => _x( \'Parent portfolio_taxonomy:\', \'portfolio_taxonomies\' ),
\'edit_item\' => _x( \'Edit portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'update_item\' => _x( \'Update portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'add_new_item\' => _x( \'Add New portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'new_item_name\' => _x( \'New portfolio_taxonomy\', \'portfolio_taxonomies\' ),
\'separate_items_with_commas\' => _x( \'Separate portfolio_taxonomies with commas\', \'portfolio_taxonomies\' ),
\'add_or_remove_items\' => _x( \'Add or remove portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'choose_from_most_used\' => _x( \'Choose from the most used portfolio_taxonomies\', \'portfolio_taxonomies\' ),
\'menu_name\' => _x( \'portfolio_taxonomies\', \'portfolio_taxonomies\' ),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'rewrite\' => true,
\'query_var\' => true
);
register_taxonomy( \'portfolio_taxonomies\', array(\'portfolio\'), $args );
}
现在我在自定义帖子类型管理面板中看到了这一点
这很好,可以很好地创建自定义帖子类型和分类法。
我还创造了two taxonomies.
现在我想在中显示投资组合two templates 根据分类法。
如果自定义帖子类型的分类是taxtemp1 然后,它应该显示在前端的第一个分类模板中。
如果自定义帖子类型的分类是taxtemp2 然后,它应该显示在前端的第二个分类模板中。
为此,我创建了两个php文件。
taxonomy-portfolio\\u taxonomies-taxtemp1。php分类法-portfolio\\u分类法-taxtemp2。php我认为它应该可以工作,但当我访问页面时,它会显示/显示在默认页面模板中。我用的是“二十一二”主题。
为什么它没有显示在我创建的正确模板上(taxonomy-portfolio\\u taxonomies-taxtemp1.php和taxonomy-portfolio\\u taxonomies-taxtemp2.php)?
但存档页面对于此自定义帖子类型很好:http://localhost/wp-test/portfolio/