Tired of tagclouds?

Here is a pretty nice snippet for your next archive template.

This code lists tags or custom taxonomies by letters in an unordered list. If you just want to list your post tags replace ‘CUSTOM-TAXONOMY’ with ‘post_tag’.

/**
 * Snippet Name: List taxonomies by initial letter
 * Snippet URL: http://www.wpcustoms.net/snippets/list-taxonomies-by-initial-letter/
 */
 $list = '';
$args = array(
  'hide_empty' => true,  // Set this to true to hide terms with no posts
);
$tags = get_terms('CUSTOM-TAXONOMY',$args);
$groups = array(  );

if( $tags && is_array( $tags ) ) {
  foreach( $tags as $tag ) {
    $first_letter = strtoupper( $tag->name[0] );
    $groups[ $first_letter ][] = $tag;
  }
  if( !empty( $groups ) ) {
    $index_line = '';
    foreach( $groups as $letter => $tags ) {
      $list .= '<ul><li><a href="#"><strong>' . apply_filters( 'the_title', $letter ) . '</strong></a></li>';
      foreach( $tags as $tag ) {
        $name = apply_filters( 'the_title', $tag-&gt;name );
        $list .= '<li><a href="' . get_term_link( $tag ) . '" title="' . sprintf(__('View all posts tagged with %s', 'yourtheme'), $tag->name) . '">' . $tag-&gt;name . ' <small>(' . $tag-&gt;count . ')</small></a></li>';
      }
      $list .= '</ul><hr/>';
    }
    $list .= '';
  }
} else $list .= '<p>Sorry, but no tags were found</p>';

print ($index_line);
print ($list);

 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x