DEV Community

Sanghun Kang
Sanghun Kang

Posted on Originally published at sanghunkang.com

Multilingual Ghost CMS Blog: 2. Making 'More Posts' Multilingual

Ghost

More posts before language filtering

When you look at a post, you can see that even if it is an English post, the show_recent_posts section at the bottom displays all posts regardless of language. Let's fix this part.

0.0.2 ยท sanghunka/ghost-multilingual-theme@0e2b7a3: Multilingual show_recent_posts_footer

Edit post.hbs

{{#get "posts" filter="id:-{{id}}" limit="3" as |more_posts|}}

    {{#if more_posts}}
        <aside class="read-more-wrap outer">
            <div class="read-more inner">
                {{#foreach more_posts}}
                    {{> "post-card"}}
                {{/foreach}}
            </div>
        </aside>
    {{/if}}

{{/get}}
Enter fullscreen mode Exit fullscreen mode

Delete the code above and add the code below.

{{#has tag="#en"}}
    {{#get "posts" filter="tag:en+id:-{{id}}" limit="3" as |more_posts|}}
        {{#if more_posts}}
            <aside class="read-more-wrap outer">
                <div class="read-more inner">
                    {{#foreach more_posts}}
                        {{> "post-card"}}
                    {{/foreach}}
                </div>
            </aside>
        {{/if}}
    {{/get}}
{{/has}}
{{#has tag="#ko"}}
    {{#get "posts" filter="tag:ko+id:-{{id}}" limit="3" as |more_posts|}}
        {{#if more_posts}}
            <aside class="read-more-wrap outer">
                <div class="read-more inner">
                    {{#foreach more_posts}}
                        {{> "post-card"}}
                    {{/foreach}}
                </div>
            </aside>
        {{/if}}
    {{/get}}
{{/has}}
Enter fullscreen mode Exit fullscreen mode

I modified the part that fetches the 3 most recent posts. If a post has the #en tag, apply filter="tag:en", and if it has the #ko tag, apply filter="tag:ko".

Result

More posts after language filtering

Only posts that match the post's language tag are shown at the bottom.

Next post

Multilingual Ghost CMS Blog: 3. Adding a Language Selector

Originally published by Sanghun Kang on Sanghun's Blog.

Top comments (0)