Improve My Related Posts Logic

Hi all,

I am using latest version of ghost and the Ruby Theme.

I have a nice looking “related posts” section on the left. However, I noticed it does not seem to be dynamic. Every page it is exactly the same. It would be cool to incorporate the tags of the post it is on, so that it is always different and pulls from related tags. Unfortunately I’m not sure how to do that. Here is the current related posts handlebars code:

{{#get "posts" limit="3" filter="tags:[{{post.tags}}]+id:-{{post.id}}"
    include="tags,authors" as |related|}}
    {{#if related}}
        <section class="related-posts">
            <h3 class="related-title">
                <span class="text">You might also like...</span>
            </h3>
            <div class="post-feed">
                {{#foreach related}}
                    {{> loop}}
                {{/foreach}}
            </div>
        </section>
    {{/if}}
{{/get}}

Hey @mlolm, the current logic shows 3 posts with the same tag as the current post excluding the current post. If it’s same for all posts on your end, your posts might be using same tags.

Here is how it works on the demo. You can see that the posts are different depending on the tags - Apple, Google and Review.

Thank you. But is it only the FIRST tag from the current post?

No, it’s from the available tags. The filter is tags:[{{post.tags}}]. For the primary tag, the filter would be primary_tag:{{primary_tag.slug}}.

{{#get "posts" limit="3" filter="primary_tag:{{primary_tag.slug}}+id:-{{post.id}}"
    include="tags,authors" as |related|}}
    {{#if related}}
        <section class="related-posts">
            <h3 class="related-title">
                <span class="text">You might also like...</span>
            </h3>
            <div class="post-feed">
                {{#foreach related}}
                    {{> loop}}
                {{/foreach}}
            </div>
        </section>
    {{/if}}
{{/get}}

tested above and it doesnt work, tested both as is above and with:

primary_tag:[{{primary_tag.slug}}]+id:-{{post.id}}

Neither work.