2014-02-05 36 views
0

這應該是非常直接的,我期待着學習如何做到這一點。排除兩個父母get_the_terms

以下代碼僅排除頂級父級。如何修改此代碼以排除下一級別?

EG:

我的分級術語是世界>國家>美國

我想顯示美國和世界沒有國家或

$terms = get_the_terms($post->ID, 'From'); 

if (!empty($terms)) { 

    $output = array(); 

    foreach ($terms as $term){ 

     if(0 != $term->parent) 
      $output[] = '<a href="' . get_term_link($term) .'">' . $term->name . '</a>'; 

    } 

    if(count($output)) 
     echo '' . __('Categories:','om_theme') . '</b> ' . join(", ", $output) . ''; 
} 

回答

0
echo '' . __('Categories:','om_theme') . '</b> ' . end($output) . ''; 
+1

還請簡單介紹一下代碼更有教育意義。 – lpapp