Skip to content

Instantly share code, notes, and snippets.

@illucent
Created March 25, 2014 19:05
Show Gist options
  • Select an option

  • Save illucent/9768902 to your computer and use it in GitHub Desktop.

Select an option

Save illucent/9768902 to your computer and use it in GitHub Desktop.
ul li counter last first taxonomy list
<?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( __( '&#40;', 'stargazer' )); ?>
<?php echo $term->count; ?>
<?php _e( __( '&#41;', '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