Possible to display an independent/initial post on the home page, independent of the "posts_per_page" loop?

Due to the aesthetic structure of a home page I’m creating I’m wondering if it would be possible to display a single (independent) post, followed by the loop of the prescribed number of posts described in the "posts_per_page" portion of the package.json file.

For example, my home page has the first post spanning the entire width of the page, followed by two rows of three posts each. As a result, there’s seven posts initially shown on the home page, but I only want loops of six extra posts to display upon hitting the “More Posts” button (as is how the theme I’m using works) so things are aesthetically ordered.

That being so, I’ve tried multiple ways to {{#get}} that initial post, outside/independent of the loop of six {{#foreach}} posts. But no matter what I try, some other problem seems to pop up.

For starters, while the initial post that is displayed is, of course, the latest post, so is the leading post of the loop of six. My attempts to exclude that first post from the loop of six posts have been successful, but then result in other problems. For example, trying to exclude the initial post from the loop of six posts doesn’t result in another post taking its place, but rather the (initial) loop being reduced from six posts to five.

I’ve tried other methods, but nothing has worked so far. Anybody know of a method for how to achieve this, if it’s even possible?

Seems to me like you’re wanting to give special treatment to a single post, which is what the featured post flag is for. You could use the get helper to pull out the first featured post and then tell the foreach to skip featured posts :slight_smile:

I believe I tried that — as a workaround, since that’s not what I’m after. Nonetheless, not only did it not work (the featured post got subtracted from the posts_per_page, if I recall correctly), but a manual fashion as such, supposing it even worked, would require the labelling of any new post as the featured post every single time. Which would be tedious, and is why I’m wondering if there’s a “proper” way to do something like this, if at all. :thinking:

I would argue that featured posts is kinda what this is best for,

However I do see the problem with it being just removed and not making up the numbers. Have you tried using the routes file to redefine the default collection? Something like this:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: featured:false

This would cause the default collection to completely ignore the featured post but respect the posts per page. You could also pull out the featured post on the home page

I have not tried nor thought of this. I’ll give it a whirl, thanks!

1 Like