I’m currently redesigning a local news website.
The old design used a whole lot of categories to handle the position of the content in the static homepage as in “top news”, “middle box”, “left box” and so on.
This is working in someway but it’s very ugly, in my opinion, very wrong on a semantic level: categories should be used to categorize.
Another option could be using sticky posts, but you can have only a “sticky” vs “non sticky” situation which is kind of limited.
I wouldn’t use custom post types: basically all post are news and it would be overkill have a separate CPT to position my content on the homepage.
The perfect solution would be:
- being able to choose between n position (I need 4)
- having a default status that puts the post on the “other news” box
- control the number of post going into a specific box: the main news box contains only one news, if there is a new “main news” the old one shouldn’t disappear from the homepage but switch to a lower position.
To recap, I’ve 5 boxes, 4 of them are a “higher level” single news container, the last one holds 10 news in a reverse chronological order. These 10 news should be “normal” news and “higher level” news pushed out from the upper boxes.
I was thinking about Advanced Custom Field as a solution to let the editor choose the position but I’m not sure it’s doable on the front end.
Thanks!
After a lot of digging and trial-error I think I found a solution.
It involves custom fields for which I used Advanced Custom Field but it’s optional.
To make things easy on the site author I put a metabox before the actual news
Now, in my homepage I have 5 areas: 4 of them contains just one news and the 5th is a “other news” box with ten new.
So the first 4 boxes are pretty easy:
with the meta value with the correct position I need.
The main issue was: how can I push older “Top1” news into the “other news” box without having to manually switch the custom field?
Maybe the code could be cleaned up a bit, but it works as I needed.
I hope that’s useful.
I would propose adding Custom Fields to the posts (either be convention or by creating a dedicated meta box) and then create the logic in front-page.php how to display them.
EDIT: To skip some posts in a query use the offset parameter:
More info in the Pagination Section of the Codex on WP_Query