How to show “Previous Category” and “Next Category” in categories archieve template [closed]

This is about PHP, not about WordPress, but here you go: get_categories returns a simple array of categories, not an indexed array. Your foreach loop tries to adress it as an indexed array. Hence the error. Also, $position becomes an undefined variable, and the loop is unnecessary anyway.

$position = array_search ($this_category->term_id, $categories);
$next_cat = $position + 1;
$prev_cat = $position - 1;

Please make sure get_categories is returning an array of ID’s and not something else.

Leave a Comment