注册自定义分类法时,只需在参数中传递URL结构。例如:
add_action( \'init\', \'register_my_taxonomy\' );
function register_my_taxonomy() {
$args = array(
//Complete the arguments for your taxonomy
// The rewrite argument should looks like this
\'rewrite\' = array( "slug" => "cars/my-tax" )
);
register_taxonomy( \'my-tax\', \'my-post-type\', $args );
}
您可能需要刷新重写规则;您只需访问wordpress管理区域中的permlink设置页面即可完成此操作。
此外,如果您有一个名为“cars”的自定义帖子类型,那么在使用URL“cars/my tax”查看前端的税务档案页面时,可能会出现PHP错误。您可以通过以下方式抑制此错误:
/*
This supress an error with Undefined property: stdClass::$labels in general_template.php
See: http://wordpress.stackexchange.com/questions/71157/undefined-property-stdclasslabels-in-general-template-php-post-type-archive
*/
add_action( \'parse_query\', \'wpse_71157_parse_query\' );
function wpse_71157_parse_query( $wp_query ) {
if ( $wp_query->is_post_type_archive && $wp_query->is_tax ) {
$wp_query->is_post_type_archive = false;
}
}