2017-12-31 130 views
0

私は、 "portfolio-category"というカスタム分類法を使用しているカスタムポストタイプを扱っています。分類法カテゴリPermalink

今、私はこのタクソミーのカテゴリを関連するパーマリンクと共にリストしようとしています。

これらのリストは問題ありません。パーマリンクを表示するための適切な用語を見つけることはできません(現在のところ、以下のコードでは#と書かれています)。ここで

は私のコードです:

<?php 
    // your taxonomy name 
    $tax = 'portfolio-category'; 

    // get the terms of taxonomy 
    $terms = get_terms($tax, [ 
     'hide_empty' => true, // do not hide empty terms 
    ]); 

    // loop through all terms 
    foreach($terms as $term) { 

     // if no entries attached to the term 
     if(0 == $term->count) 
     echo '<li><a href="#">' .$term->name. '</a></li>'; 

     // if term has more than 0 entries 
     elseif($term->count > 0) 
     echo '<li><a href="#">' .$term->name. '</a></li>'; 
    } 
?> 

答えて

0

最後に( - ごめんうるさくちょうど掲示した後)の答えを見つけました。知りたい他の誰のために

、マークアップは次のとおりです。

<?php 
    // your taxonomy name 
    $tax = 'portfolio-category'; 

    // get the terms of taxonomy 
    $terms = get_terms($tax, [ 
     'hide_empty' => true, // do not hide empty terms 
    ]); 

    // loop through all terms 
    foreach($terms as $term) { 

     $term_link = get_term_link($term); 

     // if no entries attached to the term 
     if(0 == $term->count) 
     echo '<li><a href="' .esc_url($term_link). '">' .$term->name. '</a></li>'; 

     // if term has more than 0 entries 
     elseif($term->count > 0) 
     echo '<li><a href="' .esc_url($term_link). '">' .$term->name. '</a></li>'; 
    } 
?> 
+0

してください、それは問題を解決した場合は、答えを「受け入れます」。 –

0
<?php $args = array(
    'taxonomy' => 'portfolio-category', // your taxonomy name 
    'hide_empty' => true, 
    ); 

// get the terms of taxonomy 
$terms = get_terms($args); // Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args 

// loop through all terms 
if(is_array($terms) && count($terms) > 0){ 
    $html = ''; 
    foreach($terms as $term) { 

     $term_link = get_term_link($term); 
     $html .= '<li><a href="' .esc_url($term_link). '">' .esc_html($term->name) . '</a></li>'; 
    } 
    echo $html; 
} ?> 
関連する問題