Advertisement
alchymyth

next/prev cat nav for cat archive

Apr 9th, 2011
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2. //alchyhmyth 2011
  3. //transformationpowertools.com/wordpress
  4. //
  5. //a simple next/prev category navigation for category archives
  6. //
  7. foreach(get_categories() as $all_cat) {  $cat_ids[] = $all_cat->term_id; }
  8.   $this_cat = get_query_var('cat');
  9.   $this_cat_position = array_search( $this_cat, $cat_ids ); ?>
  10.  
  11. <?php $prev_cat_position = $this_cat_position -1;
  12.       if( $prev_cat_position >=0 ) {
  13.       $prev_cat_id = array_slice( $cat_ids, $prev_cat_position, 1 );
  14.     echo '<a href="' . get_category_link($prev_cat_id[0]) . '">&laquo; ' . get_category($prev_cat_id[0])->name . '</a>'; } ?>
  15.  
  16. <?php $next_cat_position = $this_cat_position +1;
  17.       if( $next_cat_position < count($cat_ids) ) {
  18.       $next_cat_id = array_slice( $cat_ids, $next_cat_position, 1 );
  19. echo '<a href="' . get_category_link($next_cat_id[0]) . '">' . get_category($next_cat_id[0])->name . ' &raquo;</a>'; } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement