• I have some categories like 2007, 2008, 2009… The categories hold the events that took place that year.

    When I’m browsing the category 2009, I would like to have an arrow ← that you can click to get to the next/previous category.

    Can it be done?

    Thanks for all the help!

Viewing 1 replies (of 1 total)
  • Didn’t test this much but could try:

    <?php
    // for use in category template, get link to previous/next (alphabetic) categories
    if ( is_category() ) {
      $current_cat = get_query_var('cat');
      $previous = -1;
      $next = 0;
      $count = 0;
      $args = array(
        'orderby' => 'name',
        'order' => 'ASC',
        'hierarchical' => 0,
        'hide_empty' => 1
        );
      $categories = get_categories($args);
      foreach ($categories as $cat) {
        $count++;
        if ($cat->cat_ID == $current_cat) {
          $previous = $count - 2;
          $next = $count;
        }
      }
      if ($previous >= 0) {
        echo '<p>Previous category is: <a href="' . get_category_link( $categories[$previous]->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $categories[$previous]->name ) . '" ' . '>' . $categories[$previous]->name.'</a> </p> ';
      }
      if ($next > 0 && $next < count($categories)) {
        echo '<p>Next category is: <a href="' . get_category_link( $categories[$next]->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $categories[$next]->name ) . '" ' . '>' . $categories[$next]->name.'</a> </p> ';
      }
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Link from a category view to next category?’ is closed to new replies.