Wordpress 从wp_列表_类别中删除单个_目录_标题

Wordpress 从wp_列表_类别中删除单个_目录_标题,wordpress,Wordpress,如何从wp_列表_类别中删除或(排除)当前页面类别(单一类别标题) 我想从类别列表中删除当前页面类别 <?php $cat = single_cat_title( '', false ); function text_replace( $output ) { $output = str_replace( '$cat', '', $output ); return $output; } add_filter('wp_list

如何从wp_列表_类别中删除或(排除)当前页面类别(单一类别标题)

我想从类别列表中删除当前页面类别

<?php 
    $cat = single_cat_title( '', false );
    function text_replace( $output ) {
        $output = str_replace( '$cat', '', $output );
        return $output;
    }

    add_filter('wp_list_categories', 'text_replace'); ?>

<?php 
    wp_list_categories( array(
        'child_of'            => 1208,
        'current_category'    => 0,
        'depth'               => 0,
        'echo'                => 1,
        'hide_empty'          => 1,
        'hide_title_if_empty' => false,
        'hierarchical'        => true,
        'order'               => 'DESC',
        'orderby'             => 'count',
        'show_count'          => 0,
        'show_option_none'    => __( 'No categories' ),
        'style'               => 'list',
        'taxonomy'            => 'category',
        'title_li'            => 0,
        'use_desc_for_title'  => 0,

    ) ); 
?> 

您可以使用“排除”参数排除某些类别。您可以获取文章的术语,将它们放入一个数组中,然后将其传递到wp\u list\u categories查询

<?php 


$terms_to_exlude = array();
$terms = get_the_terms( get_the_ID(), 'category' );

if ($terms) { 

   foreach ($terms as $term) {

      $terms_to_exclude[] = $term->term_id;

   }

} else {

  $terms_to_exclude = '';

}

  wp_list_categories( array(
        'child_of'            => 1208,
        'current_category'    => 0,
        'depth'               => 0,
        'echo'                => 1,
        'exclude'             => $terms_to_exclude,
        'hide_empty'          => 1,
        'hide_title_if_empty' => false,
        'hierarchical'        => true,
        'order'               => 'DESC',
        'orderby'             => 'count',
        'show_count'          => 0,
        'show_option_none'    => __( 'No categories' ),
        'style'               => 'list',
        'taxonomy'            => 'category',
        'title_li'            => 0,
        'use_desc_for_title'  => 0,

    ) ); 

?> 

修复此问题:

<?php 
function text_replace($output) {
$current_category = single_cat_title("", false); 
$cat = array("$current_category");
$output = str_replace($cat, '', $output);
return $output;
}
add_filter('wp_list_categories', 'text_replace');
?>
<?php wp_list_categories( array(
    'child_of'            => 1208,
    'current_category'    => 0,
    'depth'               => 0,
    'echo'                => 1,
    'hide_empty'          => 1,
    'hide_title_if_empty' => false,
    'hierarchical'        => true,
    'order'               => 'DESC',
    'orderby'             => 'count',
    'show_count'          => 0,
    'show_option_none'    => __( 'No categories' ),
    'style'               => 'list',
    'taxonomy'            => 'category',
    'title_li'            => 0,
    'use_desc_for_title'  => 0,

) ); 

?> 

谢谢。但使用此代码后不会显示任何类别。对不起,我的英语不好。