Sign in

List of recent posts

  • This topic has 9 replies, 2 voices, and was last updated 3 weeks, 2 days ago by .
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #8168
    Avatar photomuch.fun

    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.

    --
    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!

    #8171
    Avatar photomuch.fun

    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.

    --
    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!

    #8174
    Avatar photomuch.fun
      {{#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/

    --
    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!

    #8176
    Avatar photomuch.fun

    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 photomuch.fun

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

    #8180
    Avatar photoBob

    um .. not sure if it is possible.

    --
    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!

    #8181
    Avatar photomuch.fun

    Anyway, thanks for your help, I appreciate that.

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘List of recent posts’ is closed to new replies.