Related posts in multilingual don't filter the lang

We setup the multilanguage and it works fine.

I have small problem, when I’m on an english post (ie: 47 Cold Email Tips Guaranteed to Skyrocket Your Reply Rate), the related posts at the bottom of the article are french posts.

We use the latest ghost 3.13.4 with latest casper.

Any idea to filters them so the related posts on a french articles are in french and related posts on an english post are in english?

Thank you :pray:

You might want to wrap the related posts get helper in a condition in post.hbs. Haven’t tried it, but it can be something like:

{{#has tag="#fr"}}
  {{#get "posts" filter="tags:{{primary_tag.slug}}+id:-{{id}}+id:hash-fr" limit="3" as |related_posts|}}
    ...
  {{/get}}
{{else}}
  {{#get "posts" filter="tags:{{primary_tag.slug}}+id:-{{id}}-id:hash-fr" limit="3" as |related_posts|}}
    ...
  {{/get}}
{{/has}}
1 Like

Thanks,

I just see that the problem is also in the “next_post” and “prev_post” variable that are not taking account of the “hash-fr” or not but I don’t see where these variables are defined

Maybe using the in parameter will help?

1 Like

Here’s how I tackled it

  {{!-- Links to Previous/Next posts --}}
  <aside class="read-next outer">
    <div class="inner">
      <div class="read-next-feed">
        {{#if primary_tag}}
          {{#get "posts" filter="tags:{{primary_tag.slug}}+id:-{{id}}" limit="3" as |related_posts|}}
            {{#if related_posts}}
              <article class="read-next-card">
                <header class="read-next-card-header">
                  {{#../primary_tag}}
                    <h3><span>{{#has tag="#fr"}}Plus dans{{else}}{{t "More in"}}{{/has}}</span> <a href="{{url}}">{{name}}</a></h3>
                  {{/../primary_tag}}
                </header>
                <div class="read-next-card-content">
                  <ul>
                    {{#foreach related_posts}}
                      <li>
                        <h4><a href="{{url}}">{{title}}</a></h4>
                        <div class="read-next-card-meta">
                          <p><time datetime="{{date format="YYYY-MM-DD"}}">{{date format="D MMM YYYY"}}</time> –
                            {{#has tag="#fr"}}{{reading_time minute="1 minute de lecture" minutes="% minutes de lecture"}}{{else}}{{reading_time minute=(t "1 min read") minutes=(t "% min read")}}{{/has}}</p>
                        </div>
                      </li>
                    {{/foreach}}
                  </ul>
                </div>
                <footer class="read-next-card-footer">
                  <a href="{{#../primary_tag}}{{url}}{{/../primary_tag}}">{{#has tag="#fr"}}{{plural meta.pagination.total empty="Aucun article" singular="1 article" plural="% articles"}}{{else}}{{plural meta.pagination.total empty=(t "No posts") singular=(t "1 post") plural=(t "% posts")}}{{/has}}&nbsp;→</a>
                </footer>
              </article>
            {{/if}}
          {{/get}}
        {{/if}}

        {{#has tag="#fr"}}
            {{!-- If there's a next post, display it using the same markup included from - partials/post-card.hbs --}}
            {{#get "posts" filter="tags:hash-fr+id:>{{id}}" limit="1" order="id asc"}}
              {{#foreach posts}}
                {{> "post-card-fr"}}
              {{/foreach}}
            {{/get}}

            {{!-- If there's a previous post, display it using the same markup included from - partials/post-card.hbs --}}
            {{#get "posts" filter="tags:hash-fr+id:<{{id}}" limit="1" order="id desc"}}
              {{#foreach posts}}
                {{> "post-card-fr"}}
              {{/foreach}}
            {{/get}}
        {{else}}
            {{!-- If there's a next post, display it using the same markup included from - partials/post-card.hbs --}}
            {{#get "posts" filter="tags:hash-en+id:>{{id}}" limit="1" order="id asc"}}
              {{#foreach posts}}
                {{> "post-card"}}
              {{/foreach}}
            {{/get}}

            {{!-- If there's a previous post, display it using the same markup included from - partials/post-card.hbs --}}
            {{#get "posts" filter="tags:hash-en+id:<{{id}}" limit="1" order="id asc"}}
              {{#foreach posts}}
                {{> "post-card"}}
              {{/foreach}}
            {{/get}}
        {{/has}}