Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function custom_list_terms( $taxonomies = array( 'category' ) , $args = array() ) {
- // vars
- $r = '';
- $letter = '';
- // get all terms
- $terms = get_terms( $taxonomies, $args );
- // if there are any temrs
- if ( $terms ) {
- // begin building output
- $r .= '<h2>' . $letter . '</h2>';
- $r .= '<ul class="term-archive letter-' . $letter. '">';
- // set the topmost letter to the first letter of the first term
- // $letter = mb_strtoupper( mb_substr( $terms[0]->name, 0, 1 ) ); // use this when working with non-ASCII characters
- $letter = strtoupper( substr( $terms[0]->name, 0, 1 ) );
- // loop terms
- foreach ($terms as $term) {
- // re-assign letter variable
- $old_letter = $letter;
- // get first letter of term name
- // $letter = mb_strtoupper( mb_substr( $term->name, 0, 1 ) ); // use this when working with non-ASCII characters
- $letter = strtoupper( substr( $term->name, 0, 1 ) );
- // check wether we're at a new letter
- if( $letter != $old_letter ) {
- // start a new section for new letter
- $r .= '</ul>';
- $r .= '<h2>' . $letter . '</h2>';
- $r .= '<ul class="term-archive letter-' . $letter . '">';
- }
- // sets term meta (to an empty string if function doesn't exist)
- $term_meta = function_exists( 'get_terms_meta' ) ? get_terms_meta( $term->term_id, 'mysummary', true ) : '';
- // HTML for each term
- $r .= '<li class="' . $term->taxonomy . '">';
- $r .= '<a href="/statistics/term/' . $term->slug . '" title="' . sprintf( esc_attr__( 'View all post filed under %s' ), $term->name ) . '">';
- $r .= $term->name;
- $r .= '</a> ';
- $r .= '(' . $term->count . ')';
- $r .= $term_meta; // the term meta can be appended to the HTML like this
- $r .= '</li>';
- }
- $r .= '</ul>';
- // echo/return the result
- echo $r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment