Matt-B
July 28, 2019, 6:59pm
1
I am using the last version and last configuration of Ghost
I am using all navigators, but essentially Safari
So, as you could see, I have two sections, the first one will be “latest news”, I achieve to code it as I wanted.
Now the second section is “events”, As you see there is a lot of posts, but I don’t want them all, I want like, 3 posts from all of them.
So, as I did for the first section I put the limit helper to 3.
But every time I put this, only one post of events is staying.
My code basically is this one:
------ Latest news start here -------
{{#foreach posts limit="3"}}
{{#if @first}}
my content
{{else}}
{{#if @last}}
my content
{{else}}
my content
{{/if}}
{{/if}}
{{/foreach}}
----- Events start here -----
{{#foreach posts}}. -> if I put limit="3", then only one post is here!
{{#has tag="eventos"}}
my content
{{/has}}
{{/foreach}}
Is that because I’m using “has” in the second part ?
I tested with the get helper too, but the same thing happened: only one post was there when I put limit=“3” !!
Thanks in advance for your help!!
Hey there, would you mind sharing the full code here instead of pseudo code? Worried I might be missing something
Matt-B
July 29, 2019, 5:08pm
3
Hi,
Thanks for your quick answer
Here is the full code:
{{!< default}}
{{> "featuredPosts"}}
{{> "newsletter"}}
<div id="main">
<div class="container">
<div class="row">
{{#foreach posts limit="3"}}
{{#if @first}}
<div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
<div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
{{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
<div class="gradient gradient2">
<h3><a href="{{url}}">{{title}}</a></h3>
<div class="post-tags">
{{#foreach tags limit="2"}}
<a href="{{url}}">{{name}}</a>
{{/foreach}}
</div>
<div class="share-icons">
<div class="icon-container">
{{#primary_author}}
{{#if profile_image}}
<a href="{{url}}" class="author-info">
<div class="author-image background lazy" data-src="{{profile_image}}"></div>
</a>
{{/if}}
{{/primary_author}}
<i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
<div class="icons d-none d-sm-block">
<a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
<a href="https://twitter.com/share?text={{encode title}}&url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
<a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
</div>
</div>
</div>
<div class="float-bottom">
<p>{{excerpt words="15"}}...</p>
<a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
</div>
</div>
</div>
</div>
{{else}}
<div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
<div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
{{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
<div class="gradient gradient2">
<h3><a href="{{url}}">{{title}}</a></h3>
<div class="post-tags">
{{#foreach tags limit="2"}}
<a href="{{url}}">{{name}}</a>
{{/foreach}}
</div>
<div class="share-icons">
<div class="icon-container">
{{#primary_author}}
{{#if profile_image}}
<a href="{{url}}" class="author-info">
<div class="author-image background lazy" data-src="{{profile_image}}"></div>
</a>
{{/if}}
{{/primary_author}}
<i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
<div class="icons d-none d-sm-block">
<a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
<a href="https://twitter.com/share?text={{encode title}}&url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
<a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
</div>
</div>
</div>
<div class="float-bottom">
<p>{{excerpt words="15"}}...</p>
<a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
</div>
</div>
</div>
</div>
{{#if @last}}
<div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
<div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
{{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
<div class="gradient gradient2">
<h3><a href="{{url}}">{{title}}</a></h3>
<div class="post-tags">
{{#foreach tags limit="2"}}
<a href="{{url}}">{{name}}</a>
{{/foreach}}
</div>
<div class="share-icons">
<div class="icon-container">
{{#primary_author}}
{{#if profile_image}}
<a href="{{url}}" class="author-info">
<div class="author-image background lazy" data-src="{{profile_image}}"></div>
</a>
{{/if}}
{{/primary_author}}
<i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
<div class="icons d-none d-sm-block">
<a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
<a href="https://twitter.com/share?text={{encode title}}&url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
<a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
</div>
</div>
</div>
<div class="float-bottom">
<p>{{excerpt words="15"}}...</p>
<a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
</div>
</div>
</div>
</div>
{{/if}}
{{/if}}
{{/foreach}}
{{#foreach posts}}
{{#has tag="eventos"}}
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<div class="post post-square lazy post-presentation {{#if feature_image}}background{{else}}background-pattern{{/if}}"
{{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
<div class="gradient gradient2 d-flex align-items-center">
<div class="float-top">
<div href="#" class="share-icons d-none d-sm-block">
<div class="icon-container">
<i class="fa fa-share"></i>
<div class="icons">
<a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
<a href="https://twitter.com/share?text={{encode title}}&url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
<a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
</div>
</div>
</div>
</div>
<div class="post-info">
<div class="separator"></div>
<h3><a href="{{url}}">{{title}}</a></h3>
<div class="post-tags">
{{#foreach tags limit="2"}}
<a href="{{url}}">{{name}}</a>
{{/foreach}}
</div>
</div>
<div class="float-bottom">
{{#primary_author}}
<a href="{{url}}" class="vertical-align author-info">
<div class="author-image background lazy {{^if profile_image}}author-image-fill{{/if}}" {{#if profile_image}} data-src="{{profile_image}}"{{/if}}""></div> {{name}}
</a>
{{/primary_author}}
</div>
</div>
</div>
</div>
{{/has}}
{{/foreach}}
</div>
</div>
</div>
{{pagination}}
Have you tried using the get
helper to get 3 posts with the right tag?
I think what might be happening in your case is that you’re looping through all the posts, limiting them to 3 posts and then the has
is only allowing through 1 because there’s only 1 post tagged with eventos
in those 3 posts. Does that make sense?
Matt-B
July 30, 2019, 5:23pm
5
Hi,
Thanks for you quick answer, I tried with get helper too, but it don’t work too,
I tried to tag a least 5 posts with tag eventos, when I don’t put the limit, they all show up where I want, but when I put the limit of 3, then, only one is showing up,
I understand what you are talking about, and for avoiding this, for each section, I opened with {{for each posts}}
and closed with {{/foreach posts}}
But maybe that’s not possible do do that?
Did you move all the criteria to the get
helper? You can put the tag
and limit
in there and remove the has
. Something like this:
{{#get "posts" filter="tags:eventos" limit="3" include="tags" }}
{{#foreach posts}}
<h2>{{title}}</h2>
<p>tagged: {{tags separator=", "}}</p>
{{/foreach}}
{{else}}
<p class="error">{{error}}</p>
{{/get}}
1 Like
Matt-B
July 31, 2019, 9:18pm
7
DavidDarnes:
{{#get “posts” filter=“tags:eventos” limit=“3” include=“tags” }} {{#foreach posts}}
{{title}} tagged: {{tags separator=", "}}
{{/foreach}} {{else}} {{error}}
{{/get}}
Hi,
Thanks a lot for your help, all is working fine, maybe it was because I placed the foreach
helper in the wrong place, it was like this when I tried with the get
helper:
{{#foreach posts}}
{{#get "posts" filter="tags:eventos" limit="3" include="tags" }}
<h2>{{title}}</h2>
<p>tagged: {{tags separator=", "}}</p>
{{/foreach}}
{{else}}
<p class="error">{{error}}</p>
{{/get}}
{{/foreach}}
It makes more sense with your order!
Thanks for all!
1 Like