Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Different Post ordering

  • #8809
    Avatar photo[anonymous]

    I am building a site with menus to display posts related to a tag.
    I want to display the posts in a different order depending on the menu the visitor clicks on.
    Is there a way to implement this?
    Thanks in advance for your help!

    #8815
    Avatar photoBob

    It seems to me that the easiest way to do this would be just to display tag pages.
    For example, let’s say you have posts about dogs and cats:

    1. add to the menu two items: the dog and cat tag.
    2. these pages will now display all posts related to those tags.
    #8817
    Avatar photo[anonymous]

    Of course, that’s what I did.
    But I would like to sort the posts related to cats in one way (e.g. on the date of publication) and those related to dogs on another criterion (e.g. by alphabetical order of titles).
    How do I do this?

    #8818
    Avatar photoBob

    By default, it’s not possible. But I think you can create dedicated tag-templates for dog and cat categories with the getPostsByTags helper.

    #8820
    Avatar photo[anonymous]

    It seems to be a good solution. can you guide me on how to implement it, please? I am not a developer…

    <p class=”simple-translate-result” dir=”auto”></p>
    <p class=”simple-translate-candidate” dir=”auto”></p>
    #8821
    Avatar photoBob

    I don’t have enough free time to present a complete solution, so I recommend reading the following articles:

    1. Creating custom tag template https://getpublii.com/dev/how-to-create-custom-templates/#customtagtemplates
    2. Get posts by tag helper: https://getpublii.com/dev/getpostsbytags-helper/
    #8825
    Avatar photo[anonymous]

    Here is what I made.

    1. create editorial-2-override directory
    2. copy config.json in it
    3. Add in it:
      “tagTemplates”: {
      “TEMPLATE_SLUG”: “Tri des tags par libelle”
      },
    4. choose
    5. create tag-TEMPLATE_SLUG.hbs file in the same directory by copy of tag.hbs
    6. I tried many places for the following code, without success:
      {{#getPostsByTags “count=-1&allowed=hidden,featured&tag_as=id&tags=10&orderby=modifiedAt&ordering=desc”}}
      {{/getPostsByTags}}

    I definitely don’t understand how to embed this code in the tag.hbs page… Any help will be very appreciated. Thanks in advance.