2012-06-28 2 views
2

내 워드 프레스 블로그에는 내부 작업에 사용되는 몇 가지 카테고리가 있습니다. 각 게시물 아래에있는 블로그 홈페이지 카테고리 목록에 해당 카테고리를 숨기고 싶습니다. print(the_category($postID)); 숨기거나 각 게시물 아래 해당 카테고리 목록 인쇄에 대한 필터를 만드는 방법WordPress의 게시물 아래 카테고리 목록에서 일부 카테고리를 숨기려면 어떻게해야합니까?

I 인쇄 카테고리 목록?

+0

세부 사항을 더 추가하십시오. 이러한 "내부"범주는 항상 숨기시겠습니까? ___ 등이 없으면 숨길 수도 있습니다. –

+0

Yah 나는 항상 숨기려고합니다. – Miuranga

+0

고마워; 나는 [여기] (http://codegrad.hub.ph/excluding-categories-in-wordpress-post-category-list/)에서 대답을 찾았습니다. – Miuranga

답변

2

당신이 프런트 엔드에서 선택한 범주를 숨기려면, get_the_terms 필터를 사용하려고합니다. 이 같은 것을 추가하려고 시도하십시오. functions.php

add_filter('get_the_terms', 'hide_categories_terms', 10, 3); 
function hide_categories_terms($terms, $post_id, $taxonomy){ 

    // list of category slug to exclude, 
    $exclude = array('your-term-slug', 'another-term-to-hide'); 

    if (!is_admin()) { 
     foreach($terms as $key => $term){ 
      if($term->taxonomy == "category"){ 
       if(in_array($term->slug, $exclude)) unset($terms[$key]); 
      } 
     } 
    } 

    return $terms; 
} 
1

게시물의 카테고리를 가져 와서 원하지 않는 것을 꺼낸 다음 표시해야합니다.

<?php 
$postCats = wp_get_post_categories($post->ID); 
$cats = array(); 

foreach($postCats as $c){ 
$cats[]= get_cat_name($c); 
} 
$dontShow = array("List","the","Categories","here"); 
echo implode(", ", array_diff($cats,$dontShow); 
?> 
3

내 솔루션 :

.cat-item-1 {display:none;} 
1
$exclu_categories=array(
    1=>'', 
    34 => '', 
    45=>'', 
); 
$categoires=get_the_category(); 

foreach($categoires as $category) { 

    $cat_id=$category->cat_ID; 
    $cat_name=$category->name; 

    if(!isset($exclu_categories[$cat_id])) { 
     echo $cat_name; 
    } 

} 
관련 문제