"Sectorize" sections in home page

Hi to all,

I want to “sectorize” my home page, like:

Section1 “Latest news”: only the posts with the tag “Latest news”,
After section 1:

Section 2 “events”: only posts with the tags “events”,

And so on…

I used the has helper to filter just the posts and it work well
I put the limit amount of posts I want in each section as well,

But sometimes, when I create a new post with the tag “events”, it goes in the latest news section, deleting one post of the latest news section, even if I put the limit of posts in the “latest news” section,

Why?

All I need is that the posts with specific tag go in the right section and not in another,

Thanks a lot for your help !

Hi @Matt-B, to have different sections showing posts with different tags there is no need for the has helper. Just tag your posts, and on the navigation menu use: https://yourdomain.com/tag/latest-news for all the posts tagged with the latest-news tag and https://yourdomain.com/tag/events for a section showing only the posts that are tagged with the tag events.

Hi,

Thanks for your answer, but I don’t want those sections in the navigation menu of my site,

But my site has the goal of a “news blog” and I need to put sections on the front page, as the New York Times for example, I need to put sections on the home page,

Like when I post something with a specific tag, it goes in the right section.

The problem I have here, is that when I post with a specific tag, it don’t go in the right section, even if I made html sections, and I don’t understand why,

Matt

Here the logic on how to do it @Matt-B :

  1. First get the tags on the index page by using {{#get “tags”}}
  2. Now within that get tags i just mention, do a for each tags loop. Cause you want to spread ALL the tags on the index, so you have to do a loop using {{#foreach tags}}
  3. Now within that loop i just mention on step two, open a get the posts directive using {#get “posts”}}
  4. Now within the get posts you have to another loop but this time to obtain all the posts like this: {{#foreach posts}} so you can spread all the posts, but specifically each of them within the specific tag section they belong.

Basically you have to do posts loop within a tag loop. Because first you call and do a loop for all the tags and also within each tag you do a loop to call all the posts.

It would be great to share the code you are using.

I would suggest using the #get helper, so for example, to list all the posts with the tag events, you can do something like:

{{#get 'posts' filter='tags:events' limit='4' as |posts|}}
  {{#foreach posts}}
    {{ title }}
  {{/foreach}}
{{/get}}

This is what I’m using in the Sinai theme.

1 Like

Hi,

Thanks for your help!

The solution was simple, using the get helper as you said it too. @DavidDarnes help me find the error I committed trough this: I misplaced the foreach helper!

Thanks for helping me, have a great day!

:slight_smile:

2 Likes