Okay
  Public Ticket #2134942
Exclude Posts from Specific Tag in Next/Previous Post
Open

Comments

  •  24
    Ajeet started the conversation

    Hi,

    The posts that come in Next and Previous, , I want to exclude all posts from a specific tag (or tag id=19) . For that I am trying to use {{#getPostsByTags 0 19}}

    {{#if @config.post.displayPostNavigation}} {{#checkIfAny ../previousPost ../nextPost}} <nav class="post__nav"> <div class="wrapper"> <div class="post__nav-inner"> {{#../previousPost}} 
    <div class="post__nav-prev"> <a href="{{url}}" rel="prev" class="post__nav-link"> {{#getPostsByTags 0 19}} <span>{{ translate 'post.previousPost' }} </span> <h5 class="invert"> {{title}} </h5> {{/getPostsByTags}} </a>
    </div> {{/../previousPost}} {{#../nextPost}} <div class="post__nav-next"> <a href="{{url}}" rel="next" class="post__nav-link"> <span>{{ translate 'post.nextPost' }}</span> <h5 class="invert"> {{title}} </h5> </a> </div> {{/../nextPost}} </div> </div> </nav> {{/checkIfAny}} {{/if}}


    But due to this, the Previous post gets excluded as well. Also, in the Next I still get post from tag id=19.

    Can anyone please help me out ?

    Thanks so much,

    Ajeet

  •  443
    Bob, replied

    Hi,

    I think you should also pack the "next post " section in getPostsByTags

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

  •  24
    Ajeet replied

    Hi Bob,

    Putting #getPostsByTags in "next post" and in "previous Post" makes all the posts disappear coming under next & previous. I only see a blank horizontal space instead of post links. Here is the code:

    ---

                    {{#../previousPost}}
                            <div class="post__nav-prev">
                               <a href="{{url}}" rel="prev" class="post__nav-link">
                                  {{#getPostsByTags 0 19}}
                                  <span>{{ translate 'post.previousPost' }}</span>
                                  <h5 class="invert">
                                     {{title}}
                                  </h5>
                                  {{/getPostsByTags}}
                               </a>
                            </div>
                         {{/../previousPost}}                      {{#../nextPost}}
                            <div class="post__nav-next">
                               <a href="{{url}}" rel="next" class="post__nav-link">
                                  {{#getPostsByTags 0 19}}
                                  <span>{{ translate 'post.nextPost' }}</span>
                                  <h5 class="invert">
                                     {{title}}
                                  </h5>
                                  {{/getPostsByTags}}
                               </a>
                            </div>
                         {{/../nextPost}}

    ---

    Could you please point out to any link/publiiDev guide to fix this, if possible ????

    Thanks,

  •  381
    Thomas replied

    Hi Ajeet,

    Your code means that you want to load 0 posts from tag with ID equal to 19 so it will always return empty post.

    The only way to achieve hidden posts from given tag in the next/previous posts is as I suppose a custom helper which will check if the given next/prev post has a specific tag, but it is a custom work. Also you will get an empty space in this case instead of prev/next posts, so I suppose that it will lead to the unexpected results.

    In my opinion the only pure solution to hide some posts from such navigation is adding to them "hidden" status, but of course it will have also other side effects.

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

  •  24
    Ajeet replied

    Thanks Thomas.

    Disabling Next/Prev option is the best for now.