Can someone help me? i almost finished my custom ghost theme. im trying to display related post or recents post in the bottom of my post. the problem is im trying to fetch just one of them at a time. so if there’s no related post available i want to display recents post and vice versa. but i dont want display both at a time. this what i did
{{#if post.tags}}--> im not sure what this one do but it almost works
{{#get "posts" limit="1" filter="tags:[{{post.tags}}]+id:-{{post.id}}" include="tags" as |related|}}
{{#if related}}
<section class="related-post-footer">
{{#foreach related}}
<h3>Related topic</h3>
<a href="{{url}}"><H2>{{title}}</H2></a>
<p>
{{#if meta-description}}
{{meta-description}}
{{else}}
{{excerpt words= "12"}}
{{/if}}
</p>
<a href="{{url}}">
<button type="button" class="btn">Read more →</button>
</a>
{{/foreach}}
</section>
{{/if}}
{{/get}}
{{else}}
{{#get "posts" limit="1" filter="id:-{{post.id}}" as |recents|}}
{{#if recents}}
<section class="related-post-footer">
{{#foreach recents}}
<h3>Recent post</h3>
<a href="{{url}}"><H2>{{title}}</H2></a>
<p>
{{#if meta-description}}
{{meta-description}}
{{else}}
{{excerpt words= "12"}}
{{/if}}
</p>
<a href="{{url}}">
<button type="button" class="btn">Read more →</button>
</a>
{{/foreach}}
</section>
{{/if}}
{{/get}}
{{/if}}
i’ve read this already Tutorials
i’ve tried to put get helper nested but its not working… with above code im able to display related and recents, but when i have new post with new tag it doesnt pull anything.
the other problem is when i click the related post or recents its just go back and forth. i want them to loop to my other related or recents post.
Thanks !