Created
March 25, 2014 19:05
-
-
Save illucent/9768902 to your computer and use it in GitHub Desktop.
ul li counter last first taxonomy list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php if ( is_page_template('page-gallery.php') || 'album_type' == get_post_type()) : ?> | |
| <section id="gallery_category_nav" class="widget"> | |
| <?php $taxonomy = 'album_category'; | |
| $args = array( | |
| 'orderby' => 'count', | |
| 'order' => 'DESC', | |
| 'fields' => 'all', | |
| 'hide_empty' => false, | |
| 'hierarchical' => false, | |
| 'pad_counts' => true, | |
| ); | |
| $terms = get_terms( $taxonomy, $args ); // Get all terms of a taxonomy | |
| $count = count( $terms ); | |
| $i = 1; | |
| if ( $terms && !is_wp_error( $terms )) : ?> | |
| <ul> | |
| <?php foreach ( $terms as $term ) : ?> | |
| <?php $termname = strtolower($term->name); $termname = str_replace(' ', ' ', $termname); | |
| // first item | |
| if($i == 1) { | |
| $class = 'first_cat'; | |
| // last item | |
| } elseif ($i == $count) { | |
| $class = 'last_cat'; | |
| // not first / not last item | |
| } else { | |
| $class = ''; | |
| } | |
| ?> | |
| <li class="<?php echo $class; ?>"> | |
| <a href="<?php echo get_term_link( $term->slug, $taxonomy); ?>"> | |
| <?php echo $termname; ?> | |
| </a> | |
| <span class="albumcat_count"> | |
| <?php _e( __( '(', 'stargazer' )); ?> | |
| <?php echo $term->count; ?> | |
| <?php _e( __( ')', 'stargazer' )); ?> | |
| </span> | |
| </li> | |
| <?php | |
| $i++; // raise $i by one | |
| endforeach; ?> | |
| </ul> | |
| <?php endif;?> | |
| </section> | |
| <?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment