Tag Conditionals in index loop?
-
Hi there,
I’m trying to create a new Posts/index page that lists all posts as usual, except that it highlights some of them if they have certain tags. I tried using has_tag until I realised that only checks the tags of the current page, i.e. of the index page itself, and not of the posts. Does anyone know how to check if the posts that are being listed have particular tags?
Here’s a privately published page using the page template in question, currently only displaying data for itself instead of for all posts:
https://whobackwhen.com/test-index-page/Below is what I have at the moment. Any help would be greatly appreciated.
Thanks
Ponken
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php if(has_tag('tag-1')) { ?> <div class="something"> <?php } elseif(has_tag('tag-2')) { ?> <div class="something_else"> <?php } else { ?> <div class="fallback"> <?php } ?> <?php endwhile; ?> … <?php else : ?> … <?php endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Tag Conditionals in index loop?’ is closed to new replies.