I would like to show all posts but only exclude the NEWEST post from the ‘Featured’ category, other posts from this cat should display. Any idea what I should add to the loop to achieve this? I want all other posts from other cats to be displayed aswell!
Leave a Reply
You must be logged in to post a comment.
A while back i posted a simple function that gets latest post in a certain category:
So once you have that function you can use use WP_Query or query_posts and using the
post__not_in
parameter you can exclude that post, so something like:just change $CAT_ID to the actual category id
Since by default the loop will retrieve the posts in descending order by date, you can do something like the following:
Outside the loop:
Inside the loop:
The first time a post from the Featured category is encountered (i.e. the most recent) it will be ignored and the
$featured_flag
will be set totrue
. Subsequent times through the loopthe_content()
will be displayed.Edit: To account for pagination you could change
$featured_flag
to a$_SESSION
variable. That way the true/false value will persist across multiple pages, and once it’s been set totrue
posts will continue to display properly. Thanks for pointing out the error of my ways Bainternet 🙂