#get and #has helpers combined

Hello community! Recently I am trying to fix a small bug in our page Noticias interesantes y actuales - El Fintualist - Fintualist

My problem is that we have a main featured section for latest news, and after it there are multiple sections for each of the categories we have. We don’t want a post to be on the main featured section and at the same time to be on the latest news of its category.

Right now the bug we have is that: to prevent the posts on our home to be repeated, we skip the first 5 posts on each category (but already filtered), so we are not repeating posts but our categories are outdated. You can look into our home and compare featured posts on the home versus clicking into “ver más” on its category.

Example: there is no ciencia post on the main featured, so the latest ciencia post should be on the featured ciencia ( Noticias interesantes y actuales - El Fintualist - Fintualist ). But if we go into ciencia it’s skipping the first 3 posts (even when the code says to skip 5): Noticias de Ciencia - Fintualist

So the code right now looks like this:

     <section class="container three-column__single-card-with-category">
        <div class="three-column__category-headlines">
            <h3>
                <a href="" data-link="ciencia/">CIENCIA</a>
            </h3>
            <h6>LO ÚLTIMO</h6>
            <div>
                <a href="" data-link="ciencia/" class="btn-plus">
                    {{> "buttons/ver-mas"}}
                </a>
            </div>
        </div>
        <section class="three-column-cards" style="grid-template-columns: 1fr">
            {{#get 'posts' limit="all" include="authors,tags" filter="tag:ciencia,tag:medioambiente" order="published_at desc"}}
            <section id="slider-ciencia" class="splide">
                <div class="splide__track">
                    <ul class="splide__list">
                        {{#foreach posts}}
                        {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                            {{#has number="1,2,3,4,5"}}
                                <script>console.log(num)</script>
                            {{else}}
                                {{> "single-card"}}
                            {{/has}}
                        {{/foreach}}
                    </ul>
                </div>
                <ul class="splide__pagination"></ul>
            </section>
            {{/get}}
        </section>

    </section>

It gets all post related to ciencia category, so number 1 to 5 posts are not the latest of the whole site.
After that, it uses #foreach to iterate over the posts and if it is one of the first 5 posts, it don’t apply the style. If it’s an older post it does. The problem, is that I want to apply that rule for the latest 5 posts of the whole site, not just the ciencia category.

The solution I tried is the following. Get all the posts, iterate with #foreach and do a conditional has to skip the first 5 posts. After that, use another conditional has to filter posts corresponding the category and only apply the style when it should be on it, it looked like this:

        <section class="three-column-cards" style="grid-template-columns: 1fr">
            {{#get 'posts' limit="all" include="authors,tags" order="published_at desc"}}
            <section id="slider-ciencia" class="splide">
                <div class="splide__track">
                    <ul class="splide__list">
                        {{#foreach posts}}
                        {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                            {{#has number="1,2,3,4,5"}}
                                <script>console.log(num)</script>
                            {{else}}
                                {{#has tag="ciencia,medioambiente"}}
                                    {{> "single-card"}}
                                {{/has}}
                            {{/has}}
                        {{/foreach}}
                    </ul>
                </div>
                <ul class="splide__pagination"></ul>
            </section>
            {{/get}}
        </section>

My problem is that it didn’t retrieve any post on the featured category section.

Please let me know if you have any other solution that may work.
Thanks,
M

1 Like

I like the site design. Have you found the docs on get helpers?

With filters, you can combine and negate them, so you should be able to express that you would like the 5 most recent ciencia posts that are not featured.

1 Like

hello! @markstos

yes, i looked into the documentation and seems that I’m doing it correct. Our featured posts are based on date and some categories so I can’t filter by tag=“-featured”.

Maybe it is something with combining this?:
#get (all posts)
> #foreach
> #has number="1, 2, 3, 4
do nothing
> else
> #has tag="list, of, tags"
apply style

What about this:

{{#get "posts" limit="all" include="tags,authors"}}
  {{#foreach posts from="6"}} 
    {{#has tag="list"}}
    {{/has}}
   {{/foreach}}
{{/get}}

Note that depending on the size of your site, this get helper could be an expensive operation. I’d recommend changing “all” to a smaller number depending on your needs so you don’t run into any performance issues.

1 Like

hello Ryan!

Your code seems cleaner than what I was trying, but still have the same problem (it works locally but doesn’t work on staging)

As you can see, if I limit #get to 80 post, our less published categories have really old posts that are not showing, so I have to limit to “all”. But that doesn’t seem to be the problem because it still doesn’t show posts on our staging domain:

Our staging domain so you can check no posts are shown: Home Chile - Fintualist

Do you know if there is any method to #get all posts with tags filter, but ignore the general first 6 posts (ignoring the tags filter)?

Thanks and please let me know if there is any other solution.

I’ll keep digging into this

1 Like

May I ask how you figured it out @Matias_Guerrero?

I’m facing the same issue and it kills our fundamentals on UX (we love to simplify).

No, it didn’t work.

I think ghost confirmed it was a bug on their side but not sure if they fixed it

1 Like