How to exclude posts with a certain tag
-
Some of my posts are tagged with a certain tag, and I wish to exclude all posts with that tag from appearing in the_loop on my home page.
Ultimately, the basic code to do so is:
<?php while (have_posts()) : the_post(); if (has_tag('Twitter') && is_home() ) continue; ?>
Thus, if the post has the tag (in this case, “Twitter”) and this is the home page, then it will skip it.
(Hopefully this information is useful to someone else as well; there’s a lot of info about how to do this with categories, but not much with tags, which seem to work slightly differently.)
So, that’s the part I’ve solved — here is the part I have not solved: My query is set to show an exact number of posts:
<?php query_posts("showposts=6"); ?>
…and when I use the code shown above to exclude a post, it throws off the number of posts shown. For example, if, among those 6 posts, one is tagged “Twitter”, then only 5 posts are shown. If two are tagged “Twitter”, then only 4 posts are shown.
How to I exclude a post, yet keep the number of posts at 6?
- The topic ‘How to exclude posts with a certain tag’ is closed to new replies.