2014-03-05 2 views

답변

1
foreach (get_the_category() as $cat) { 
    $parent = get_category($cat->category_parent); 
    if (!get_category($cat->category_parent)) { 
     // do something with the category, like use it to create a new query_posts or something 
    } 
} 
+1

나를 위해 작동하지 않습니다 – user3383480

+0

아래 답변을 시도하십시오 ... –

1

카테고리를 가져 와서 각 항목에 대해 parent 필드를 확인할 수 있습니다.

<?php 
    $categories = get_the_category(); 
    if($categories){ 
     foreach($categories as $category) { 
      if ($category->parent < 1) { 
       // Your action here 
      } 
     } 
    } 
?> 
관련 문제