Is there a simple elegant way to order posts by "featured first" on the index page?

Hello Ghost Community!

I’m using foreach to iterate over all my posts and list them on my index.hbs. This a screenshot of my code:

That works fine.The posts are listed 11 at a time, then at the bottom users see a “view more” button. So they can see the next 11 posts, etc.

But i am wondering what is the easiest and most elegant way to first show all the posts that are featured on my index page. Of course 11 at a time (like its been done right now), and still have the pagination.
I want to show first all the posts that are featured and then the ones that are not.

I was reading about the get functional helper on the handlebars documentation and also the how to build a related posts block tutorial

Those instructions gave me the idea to use something like this code:

54%20AM

Right before my foreach code block on my index.hbs so that the featured posts will be shown first and above of the regular posts. So now i see on my index page all my featured posts, and then my regular ones. The problem with that approach is that the featured posts are not linked to the pagination logic. For example if i ve had 50 featured posts, of course i could limit them (on the code above they are limited to three) but i want them to be intertwined with the pagination of the regular posts.

So i guess a more elegant solution oughta exists so that the regular posts are just ordered by showing first all of those posts who are featured. Should i be fiddling with the YAML configuration to achieve this?
Can someone point me in the right direction please?

I am using 2.25.0

Hey @lmuzquiz! You can configure this kind of ordering with the routes.yaml file. You can set order to be featured desc, published_at desc. More information can be found on our docs:

4 Likes

Its amazing, all i had to do was open the YAML file and add one line: order: featured desc, published_at desc

Thanks you so much David. The URLs & Dynamic Routing Ghost capabilites are beautiful.

5 Likes

Thank you! So glad I was able to help