【问题标题】:Exclude specific categories from category list从类别列表中排除特定类别
【发布时间】:2014-05-18 19:08:01
【问题描述】:

以下是我在此页面上显示的类别列表的代码

http://www.surefiresearch.com/blog/

我想删除类别“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;
}

【问题讨论】:

  • 这可能是你不能在同一个调用中使用includeexclude作为条件(不确定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


【解决方案1】:

这就是我要找的,排除命令有效

wp_list_categories('orderby=name&show_count=1&exclude=66,67,68,69,70,71&title_li=');

【讨论】:

    猜你喜欢
    • 2014-12-27
    • 1970-01-01
    • 2021-02-02
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多