I use Extra theme from Elegant themes. One of specific functions of this theme is category layout builder, which creates archives posts based on taxonomy.
I have created such layout pages based on tags (that page only posts only with some certain tag are shown). There will be more than 20 similar pages, just with posts based on different tag. Now I want to insert a shortcode to show links to these previous and next archive pages (get previous and next archive pages) based on tags.
Current tag I get with code:
$tag = get_the_tags();
if ($tags){
foreach( $tags as $tag ) :
echo("<script>console.log('PHP: ". $tag->slug ."');</script>");
endforeach;
}
a whole tag list I get with:
$all_tags = get_tags(array('get'=>'all'));
if($all_tags) {
foreach ($all_tags as $listtag):
echo("<script>console.log('PHP: ". $listtag->slug ."');</script>");
endforeach;
} else {
_e('No tags created.', 'text-domain');
}
How could I get previous and next tags? Also, I want to get last tag of tag array if I am already on first tag and looking for previous tag (accordingly to get first tag when I am on the last tag and looking for next tag).
I understand I should retrieve a whole tag array and then get position of current tag in that tag array. Then to get tag with 'current tag position - 1' and 'current tag position + 1'. I have searched for that, tried to implement idea of similar solutions based on categories (like How to get next previous category in same taxonomy?, Is it possible to put next and previous category links? etc) with no luck.
I am based on javascript (that you see from my code to insert console), so my questions might sound a bit crazy.