【发布时间】:2014-05-18 19:08:01
【问题描述】:
以下是我在此页面上显示的类别列表的代码
我想删除类别“page-seo”和“page-seo-1”。我正在尝试使用“exclude=cat_id”来阻止实际帖子显示在此页面上,但它不适用于类别列表。
谁能看出我做错了什么?
干杯。
$taxonomy = 'category';
// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = ', ';
if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
$term_ids = implode( ',' , $post_terms );
$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids . '&exclude=66,67');
$terms = rtrim( trim( str_replace( '
', $separator, $terms ) ), $separator );
// display post categories
echo $terms;
}
【问题讨论】:
-
这可能是你不能在同一个调用中使用
include和exclude作为条件(不确定wp_list_categories,但对于其他函数来说确实如此,例如wp_tag_cloud)。如果您从$post_terms中删除 ID 66 和 67 并仅使用include,会发生什么情况? -
这有效 wp_list_categories('orderby=name&show_count=1&exclude=66,67,68,69,70,71&title_li=');
标签: php wordpress categories