Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pixelstorm/5c50027e56646d732abea2c47f8096a5 to your computer and use it in GitHub Desktop.
Save pixelstorm/5c50027e56646d732abea2c47f8096a5 to your computer and use it in GitHub Desktop.
get list of terms for custom post type taxomomy and output as nav links
<?php
//get list of linked terms to custom post type categories / terms
//change the first parameter of the $terms = get_terms( $term, $args ); to the taxomomy name you want to pull from
function cpt_category_nav($term) {
$args = array( 'hide_empty=0' );
$terms = get_terms( $term, $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<nav><ul>';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<li><a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a></li>';
if ( $count != $i ) {
$term_list;
}
else {
$term_list .= '</ul></nav>';
}
}
echo $term_list;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment