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