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.

List of recent posts

  • #8168
    Avatar photo[anonymous]

    Hi there,

    I’d like to publish a list of e.g. the 5 most recent posts. All documentation/forum topics I found are about @website.contentStructure.posts, which shows a list of all posts. How can I restrict @website.contentStructure.posts to 5 items ?

    In addition, can I put the @website.contentStructure.posts in the sidebar.hbs ?

    And, another thought, is possible to show 5 random posts ?

    Thanks in advance, Michael

    #8169
    Avatar photoBob

    Let me take a peek inside a code snippet to see how it is made.

    #8171
    Avatar photo[anonymous]

    ok, here you are:

    This gives me a list of alle posts in the sidebar. how to reduce the count of posts to the 5 newest, or 5 random posts ? Thanks, Michael

    #8173
    Avatar photoBob

    Paste a code snippet into the Code Insert popup.

    #8174
    Avatar photo[anonymous]
      {{#each @website.contentStructure.posts}}
    • {{title}}
    • {{/each}}
    #8175
    Avatar photoBob

    Ok, I got it. Use the @index variable to limit the number of posts.
    Have a look at this: https://getpublii.com/dev/how-to-display-posts-connected-with-a-specific-tag-name/

    #8176
    Avatar photo[anonymous]

    Thanks, Bob, it works 🙂

    As a documentation for other users, only:

    <div>
       <ul>
          {{#each @website.contentStructure.posts}}
             {{#checkIf @index '<' 5}} 
                <li>
                   <a href="{{url}}" rel="nofollow">
                      <strong>{{title}}</strong>
                   </a>
                </li>
             {{/checkIf}}
          {{/each}}
       </ul>
    </div>
    #8178
    Avatar photo[anonymous]

    Bob, do you have a suggestion for the “5 random posts” thing, too ?

    #8180
    Avatar photoBob

    um .. not sure if it is possible.

    #8181
    Avatar photo[anonymous]

    Anyway, thanks for your help, I appreciate that.