Category and Tag Display Function
The first function ‘avp_get_terms()’ was written to display the category and tag elements in columns. It collects all the specified taxonomies (categories or tags) and sorts them into groups based on their first letter. Then it displays the data by groups, showing the key letter of the group beside the list. The data is divided into columns based on the number of columns indicated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /* * Function adds an alphabet listing of your categories or ppost tags to the page. * Original version by Patriek Jeuriens (http://www.pressessentials.com/ ), based on the code posted by Mfields on the wordpress forums. */ function avp_get_terms( $taxonomy = ‘post_tag’, $columns = 2 ) { $tags = get_terms( $taxonomy, “hide_empty=1” ); $style = sprintf( ‘width: %d%%;’, ( 100 / ( min( max( $columns, 2 ), 5 ) ) ) ); $counter = 0; $columnnumber = 1; $columnbreak = ceil( count( $tags ) / ( min( max( $columns, 2 ), 5 ) ) ) + 1; $groups = array(); foreach ( $tags as $tag ) { $groups[ strtoupper( $tag->name[ 0 ] ) ][] = $tag; } echo ‘<div class=“sitemap-index-container”>’; echo ‘<div class=“sitemap-index-column” style=“ ‘ . $style . ’ ”>’; foreach ( $groups as $letter => $tags ) { /* * Prevent small orphans at the bottom of the div section */ if ( ( $counter + min( count( $tags ), 3 ) ) > ( $columnbreak * $columnnumber ) ) { $counter ++; echo ‘</div><!– end column –>’; echo ‘<div class=“sitemap-index-column” style=“ ‘ . $style . ’ ”>’; $columnnumber ++; } echo ‘<div class=“sitemap-index-capital”>’ . apply_filters( ‘the_title’, $letter ) . ‘</div>’; echo ‘<ul class=“sitemap-index-list”>’; foreach ( $tags as $tag ) { $counter ++; if ( $counter >= ( $columnbreak * $columnnumber ) ) { echo ‘</ul>’; echo ‘</div><!– end column –>’; echo ‘<div class=“sitemap-index-column” style=“ ‘ . $style . ’ ”>’; $columnnumber ++; echo ‘<div class=“sitemap-index-capital”>’ . apply_filters( ‘the_title’, $letter ) . ‘</div>’; echo ‘<ul class=“sitemap-index-list”>’; } $url = attribute_escape( get_term_link( $tag, $taxonomy ) ); $name = apply_filters( ‘the_title’, $tag->name ); echo ‘<li class=“sitemap-index-item”>’; echo ‘<a href=“ ‘ . $url . ’ ”>’ . $name . ‘</a> (‘ . intval( $tag->count ) . ’)’; echo ‘</li>’; } echo ‘</ul>’; } echo ‘</div><!– end column –>’; echo ‘</div><!– end section –>’; echo ‘<br style=“clear: both;” />’; } ?> |
This the companion CSS style sheet file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | @charset “utf‑8”; /* CSS Document */ #sitemap-index-container { display:inline; margin: 0px 0px 0px 0px !important; } .sitemap-index-column { float: left; margin-right: 0,5em; } .sitemap-index-list{ list-style: none; padding: 3px 0px 0px 3px !important; margin: 0px 0px 20px 15px !important; } .sitemap-index-capital{ float: left; margin: 0px; padding: 0px; font-family: Georgia, “Times New Roman”, Times, serif; font-size: 1.25em; } .sitemap-index-item { font-size: 0.9em; margin: 0px 0px 0px 5px; } |
The function is based on a plugin by Patriek Jeuriens, based on the code posted by Mfields on the wordpress forums.
The short URL of the present article is: http://www.terryobrien.me/1i3n4
Personal Links