2017-12-31 124 views
0

Ich arbeite an einem benutzerdefinierten Post-Typ, der eine benutzerdefinierte Taxonomie namens "Portfolio-Kategorie" verwendet.Taxonomie-Kategorie Permalink

Jetzt versuche ich die Kategorien unter dieser Taxonomie aufzulisten - mit dem entsprechenden Permalink.

Das Auflisten von ihnen ist in Ordnung - scheint nicht die richtigen Begriffe zu finden, um den Permalink anzuzeigen (derzeit als # auf dem Code unten angegeben).

Hier ist mein Code:

<?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>'; 
    } 
?> 

Antwort

0

Schließlich die Antwort gefunden (ärgerlicherweise kurz nach der Veröffentlichung - sorry).

Für jemand anderes wissen wollen, das Markup ist:

<?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

Bitte "accept" die Antwort, wenn sie das Problem gelöst. –

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; 
} ?>