Is it possible to put next and previous category links?

Not sure if this is what you want, gets all the categories and outputs a link to the next and previous in the order returned from get_categories():

$this_category = get_queried_object();
$categories = get_categories();

foreach( $categories as $position => $cat ) :
    if( $this_category->term_id == $cat->term_id ) :
        $next_cat = $position + 1;
        $prev_cat = $position - 1;
        break;
    endif;
endforeach;

$next_cat = $next_cat == count($categories) ? 0 : $next_cat;
$prev_cat = $prev_cat < 0 ? count($categories) - 1 : $prev_cat;

echo 'previous: ' . get_term_link( $categories[$prev_cat] );
echo 'next: ' . get_term_link( $categories[$next_cat] );

Leave a Comment