Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created February 8, 2016 04:44
Show Gist options
  • Save hsleonis/43b2eb3a7bc9cb6ffe6f to your computer and use it in GitHub Desktop.
Save hsleonis/43b2eb3a7bc9cb6ffe6f to your computer and use it in GitHub Desktop.
Print list of all terms of a given taxonomy with link
<?php
$args = array( 'hide_empty=0' );
$terms = get_terms( 'status', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<ul class="spec-project-cat-ul">';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<li class="col-xs-4 remove-padding"><a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all %s projects', 'themeaxe' ), $term->name ) ) . '">' . $term->name . '</a></li>';
if ( $count != $i ) {
$term_list .= '';
}
else {
$term_list .= '</ul>';
}
}
echo $term_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment