我使用以下代码创建了自定义帖子类型:
add_action( \'init\', \'create_team_post_type\' );
function create_team_post_type() {
register_post_type( \'portfolio\',
array(
\'labels\' => array(
\'name\' => __( \'Portfolio\' ),
\'singular_name\' => __( \'Portfolio\' )
),
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'taxonomies\' => array(\'portfolio_category\'),
\'supports\' => array(\'title\',\'editor\',\'thumbnail\')
)
);
}
使用以下代码进行分类:
function taxonomies_portfolio() {
$labels = array(
\'name\' => _x( \'Portfolio categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Portfolio categories\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Query portfolio categories\' ),
\'all_items\' => __( \'All portfolio categories\' ),
\'parent_item\' => __( \'Parent category\' ),
\'parent_item_colon\' => __( \'Parent category:\' ),
\'edit_item\' => __( \'Edit portfolio category\' ),
\'update_item\' => __( \'Update portfolio category\' ),
\'add_new_item\' => __( \'Add Edit portfolio category\' ),
\'new_item_name\' => __( \'New portfolio category\' ),
\'menu_name\' => __( \'Categories\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'rewrite\' => true
);
register_taxonomy( \'portfolio_category\', \'portfolio\', $args );
}
add_action( \'init\', \'taxonomies_portfolio\', 0 );
当我单击导航到的类别时
index.php
. 我创建了一个名为
taxnomy-portfolio_category.php
. 正在显示URL
url/taxnomy-portfolio_category.php/cat_name
但结果是
index.php
.
最合适的回答,由SO网友:TrubinE 整理而成
自定义分类法的层次结构如下所示:
taxonomy-{taxonomy}-{term}.php
: 例如,如果分类法名为“sometax”,而分类法的术语为“someterm”,WordPress将查找名为taxonomy sometax someterm的文件。php。
taxonomy-{taxonomy}.php
: 例如,如果分类法名为“sometax”,WordPress将查找名为taxonomy sometax的文件。php
taxonomy.php
archive.php
index.php
url:
/you_site.com/portfolio_category/term_name
前提是设置管理->设置->永久链接已找到:
/%category%/%postname%.html