在wordpress博客上全局隐藏(不删除)类别名称


Hide (not remove) category name globally on wordpress blog

我试图在我的整个wordpress博客上隐藏一个特定的类别名称(例如称为"Featured")。请注意,我不想排除属于该特定类别的帖子,我只想防止实际类别名称出现在任何地方,它应该是不可见的。

我找到了一个代码片段,我把我的函数。php,实际上它确实是我想要的,但它只是隐藏类别名称从后元部分,它没有任何影响的第三方插件类别名称仍然显示。你能帮助为了得到这个特定的插件工作吗?

function.php中隐藏类别名称的代码:
function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
    $exclude = array('featured');
    $cats = explode($separator,$thelist);
    $newlist = array();
    foreach($cats as $cat) {
        $catname = trim(strip_tags($cat));
        if(!in_array($catname,$exclude))
            $newlist[] = $cat;
    }
    return implode($separator,$newlist);
} else
    return $thelist;
}
add_filter('the_category','the_category_filter',10,2);

Plungin的函数是这样的:

private function generate_post_categories( $post ) {
    // Setting up category list string.
    $post_cat_string = '';
    // Setting up category list.
    $post_cat_list = '';
    // Fetching post category prefix  with WPML support.
    $post_category_prefix = ($this->icl_t) ? icl_t('ORP Post Category Prefix', 'post-category-prefix–' . $this->widget_id, $this->widget_args['post_category_prefix'] ) : $this->widget_args['post_category_prefix'];
    // Checking for post category PREFIX.
    if ( !empty( $this->widget_args['post_category_prefix'] ) ) {
        // Building post category PREFIX HTML.
        $post_cat_string .= esc_html( $post_category_prefix );
    }
    // Retrieving categories array.
    $orp_categories = get_the_category( $post->ID );
    // Checking if "post category link" option is on.
    if ( 'yes' == $this->widget_args['post_category_link'] ) {
        // Looping through categories array.
        foreach( $orp_categories as $orp_cat ) {
            // Fetching the current category link.
            $orp_category_link = get_category_link( $orp_cat->cat_ID );
            // Building HTML link atts.
            $linkatts = array(
                'href'  => $orp_category_link,
                'title' => $orp_cat->cat_name
            );
            // Building category link HTML.
            $post_cat_list .= $this->orp_create_tag( 'a', $orp_cat->cat_name, $linkatts ) . esc_html( $this->widget_args['post_category_separator'] );
        }
    } else {
        // Looping through categories array.
        foreach( $orp_categories as $orp_cat ) {
            // Filling categories list.
            $post_cat_list .= $orp_cat->cat_name . esc_html( $this->widget_args['post_category_separator'] );
        }
    }
    // Right trimming the last category separator on the category list.
    $post_cat_string .= rtrim( $post_cat_list, esc_html( $this->widget_args['post_category_separator'] ) );
    // Returning the post category HTML.
    return $this->orp_create_tag( 'div', $post_cat_string, array( 'class' => 'orp-post-category' ) );

你能试着改变这部分吗?

// Looping through categories array.
foreach( $orp_categories as $orp_cat ) {

:

// Looping through categories array.
foreach( $orp_categories as $orp_cat ) {
  if($orp_cat->cat_name == 'Featured') {
    continue;
  }

如果类别名称等于"Featured",则应该跳过循环。