Sign in

how to create a list of last updated posts

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

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

    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 photogpsblues

    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/

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