2014-03-05 40 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 
      } 
     } 
    } 
?> 
相關問題