Next and previous links category infinite loop

I wish create a next previous category navigation.
I found an old post on stackexchange (2012) about category navigation but it’s returning an error.

So I made something like this:

$category = get_the_category();
$name= $category[0]->name;
$slug= $category[0]->slug;
$id = $category[0]->cat_ID;

$previouscat = $id – 1;
$nextcat = $id + 1;
$category_link_next = get_category_link( $nextcat );
$category_link_previous = get_category_link( $previouscat );
?>

<a href=”<?php echo $category_link_previous ?>” class=”btnSuivPrec btnPrec”><span class=”icon-precedent”></span></a>
<div class=”picto colo<?php echo $slug ?>”>
<span class=”icon-<?php echo $slug ?>”></span>
</div>
<a href=”<?php echo $category_link_next ?>” class=”btnSuivPrec btnSuiv”><span class=”icon-suivant”></span></a>

But how to modify the code to have an infinite loop ?

Read more here:: Next and previous links category infinite loop

Leave a Reply

Your email address will not be published. Required fields are marked *