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.

how to create a list of last updated posts

  • #9098
    Avatar photo[anonymous]

    Dear all –

    I would like to list posts which I updated. For the most recent posts I use this

    {{#each @website.contentStructure.posts}}
    {{#checkIf@index'<‘5}}
    but how to list the last updated posts ?
    #9138
    Avatar photo[anonymous]

    Hi –

    I used a different approach, and tried to help myself 🙂

    I followed the instructions this page: https://getpublii.com/dev/yearly-archive-for-posts/ and changed createdAt to modifiedAt.

    Working this way gives me a list of all modified posts for 2023, for example.

    What I still need

    • is a hint on how to limit the list to 5,
    • and on how to order the list in a timely manner…

    Cheers, Michael

    The screenshot shows the result I get by now

    A) the .hbs part:

    
    
      {{#each (yearsInArchive 2023)}} {{#if (getPostsByYear @website.contentStructure.posts this)}} {{#each (getPostsByYear @website.contentStructure.posts this)}}
    • {{date modifiedAt "YYYY-MM-DD"}}
    • {{/each}} {{/if}} {{/each}}

    B) and the helpers script:

    let themeHelpers = {
        yearsInArchive: function (startYear) {
            let years = [];
            let currentYear = new Date().getFullYear();
            for (let i = currentYear; i >= startYear; i--) {
                years.push(i);
            }
            return years;
        },
        getPostsByYear: function (posts, year) {
            return posts.filter(post => new Date(post.modifiedAt).getFullYear() === year);
        }
    };
    module.exports = themeHelpers;
    #9143
    Avatar photo[anonymous]

    Hi much.fun,

    Have you tried a simple getPostsByTags?

    {{#getPostsByTags “count=5&allowed=hidden,featured&tag_as=id&tags=1,2,3&orderby=modifiedAt&ordering=asc”}}
    <h2>{{ title }}</h2>
    {{/getPostsByTags}}

    https://getpublii.com/dev/getpostsbytags-helper/