I administrate a website(www.teknologia.no) running WordPress. As you can see on the front page I have a “main/featured” article on the top of the page showing the latest post from a specific category. And beneath it I have the main loop showing all the latest posts from all categories.
But as you can see and read from the title, when a posts is chosen to be places in the featured space on the top, it is also shown in the latest posts feed.
My question is as my title say: How can I exclude the newest/latest post in a certain category from appearing with the all the latests posts.
I know I can manually control this by changing the categories after a while and such, but I want it to be done automatically, and I don’t know how.
Hope you can spare some time and help me 🙂
You would need to update the template’s logic so that the main loop skips outputting the post that’s output at the top.
Without seeing your template code, it’s hard to be specific, but something like this would probably work:
In the top section, save the ID of the post that you’re outputting:
If you need to directly fetch the ID of the latest post in a given category, rather than saving it during the loop, you can do it like this instead, using WP_Query:
Then, in the main loop, either alter the query to exclude that post:
or manually exclude it inside the loop, something like this:
More information here, here and here.
here is a function that does just that:
}
Usage: say my category id is 22 then:
you can also pass an array of categories to this function.
Initiate a variable and check inside your loop. A simple way:
for that you can use
for more info : blog
Method – 1
Method – 2
This query is telling the loop to only display 5 posts which follow the most recent first post. The important part in this code is âoffsetâ and this magic word is doing the whole thing.
More details from Here
Exclude first one From latest five posts