Sign in

Making custom helper; how does Publii order posts?

  • This topic has 1 reply, 2 voices, and was last updated 3 weeks, 3 days ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7777
    aliengeo

    I’m trying to make a custom helper that will link to the first and last posts in a listing of unknown length. (Specifically: the published unhidden post for which there are no previous posts, and the published unhidden post for which there are no later posts.)

    To make this work, I need to know: how does Publii determine which posts come before or after other posts in the listing? Like, they can be sorted in 8 different ways, so is there a sort-agnostic function that tells Publii how to order the posts, or is the sort type and direction hardcoded in?

    #7839
    gpsblues

    Hi,
    Maybe you could use 2 helpers #getPostsByTags (https://getpublii.com/dev/getpostsbytags-helper/).

    {{#getPostsByTags “count=1&tag_as=id&tags=1,2,3&orderby=id&ordering=asc”}}
    <p>First post:</p>
    <h2>{{ title }}</h2>
    {{/getPostsByTags}}

    {{#getPostsByTags “count=1&tag_as=id&tags=1,2,3&orderby=id&ordering=desc”}}
    <p>Last post:</p>
    <h2>{{ title }}</h2>
    {{/getPostsByTags}}

    In this case the “tags” parameter creates the list of posts. Sorting is based on the post ID.
    If you don’t use the “allowed” parameter, hidden posts are excluded.

     

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.