2017-04-19 30 views
0

我有一個WP網站的投資組合部分。 在投資組合頁面上顯示項目類別。 我想僅顯示id = 63的父類別的子類別。WordPress的投資組合:只顯示子類別

這是當前的代碼:

<?php $terms = get_the_terms($post->ID , 'portfolio_category', 'string'); ?> 
    <?php $num_of_terms = count($terms); ?> 

      <?php if($terms) { ?> 
      <div class="meta-column"> 
        <strong class="caps"><?php esc_html_e('Artist', 'onioneye'); ?><span class="colon">:</span></strong> 
        <span> 
         <?php 
          $i = 0; 

          foreach($terms as $term) { 

           if($i + 1 == $num_of_terms) { 
            echo esc_html($term -> name); 
           } 
           else { 
            echo esc_html($term -> name . ', '); 
           } 

           $i++; 
          } 
         ?> 
        </span> 
       </div> 

      <?php } ?> 

回答

0

你能試試這個:

$args = array('child_of' => 63); 
$terms = get_categories($args); 
代替這個

$terms = get_the_terms($post->ID , 'portfolio_category', 'string'); 
+0

謝謝,但沒有奏效。 –