你想要的是an index page for custom taxonomies. 有a ticket for that, 但目前还不清楚在这一页上最明显的是什么:1)该分类法任何术语的所有帖子列表,或2)该分类法所有术语的列表?记住这一点category
也是一种分类法,但假设所有帖子都属于至少一个类别(带有Uncategorized
默认设置)。在这种情况下,选项1将与常规post查询相同,选项2可能更有意义。
自定义帖子类型索引页的相关问题will be fixed in the upcoming 3.1 release.
我自己尝试了一些东西,而不是干涉request
hook,我认为更好的方法是添加新的重写规则并修改查询:
add_action( \'init\', \'wpse4663_init\' );
function wpse4663_init()
{
// The custom taxonomy rewrite rules end up at the top of the rewrite array
register_taxonomy(
\'wpse4663\',
array( \'post\' ),
array(
\'label\' => \'WPSE 4663\',
)
);
// So there probably is no danger in adding this specific rewrite rule there too
// We re-use the existing `taxonomy` query var, but with no `term`
// We clean this up in `parse_query`, otherwise get_posts() complains
// You could make this work for all taxonomies (categories, tags, ...) by doing this repeatedly
// But then it\'s probably better to do this in the `rewrite_rules_array` filter
add_rewrite_rule( \'wpse4663(/page/([0-9]+))?/?$\', \'index.php?taxonomy=wpse4663&paged=$matches[2]\', \'top\' );
}
add_filter( \'parse_query\', \'wpse4663_parse_query\' );
function wpse4663_parse_query( &$wp_query )
{
// is_tax is only true if both a taxonomy and a term are set, otherwise is_home is true
// But we don\'t want that: is_tax and is_archive should be true, is_home should be false
if ( !$wp_query->is_tax && $taxonomy_query = $wp_query->get( \'taxonomy\' ) ) {
foreach ( $GLOBALS[\'wp_taxonomies\'] as $taxonomy => $t ) {
if ( $t->query_var && $taxonomy_query == $t->query_var ) {
// Make sure the conditional tags work, so the right template is loaded
$wp_query->is_tax = true;
$wp_query->is_archive = true;
$wp_query->is_home = false;
// Make is_tax($taxonomy) work
$wp_query->queried_object = $t;
$wp_query->queried_object->taxonomy = $taxonomy;
// If term is null, get_terms (query.php line 2043) will get all terms of this taxonomy
$wp_query->set( \'term\', null );
break;
}
}
}
}