Sign in
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.

Show random posts

  • This topic has 5 replies, 3 voices, and was last updated 3 months, 3 weeks ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10437
    Avatar photofinrik

    I would like to add a list of links with random posts on my website. But only posts with certain tags should be considered. With “getPostsByTags” I get the posts back correctly.

    Is there a way to sort them randomly now? Note: By random I don’t mean dynamically on the web page. It is enough if it is randomly sorted on each export.

    Thanks a lot!

    {{#getPostsByTags "count=100&&tag_as=id&tags=7"}}
    
    {{ title }}
    
    {{/getPostsByTags}}

     

    #10506
    Avatar photoTomasz Dziuda

    Hi,

    Unfortunately at this moment this helper not supports random ordering – I will consider to add it for next release

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

    #10513
    Avatar photofinrik

    Thank you very much! This is great.

    #10516
    Avatar photocandidexmedia

    I’d love to also be able to click on a menu item to go to a random post every time the button is clicked, kind of like how tumblr does it. I wonder if that’s possible already…

    #10518
    Avatar photoTomasz Dziuda

    @candidexmedia – it is a possible solution which I have prepared with ChatGPT: https://chat.openai.com/share/f9384d04-be55-4091-836a-1bc8d49142a0 🙂

    My prompt is below in case if this link would expire in the future:

    Please prepare a JavaScript script, which will work in the following way:

    When user will click a link with `#random` set as `href` attribute:
    – add class “is-loading” to the clicked link
    – please retrieve the sitemap.xml file from the website domain (you can assume that sitemap.xml file is always in the root directory of the domain)
    – get a list of subpages from the sitemap
    – remove from the list subpages listed on the blacklist array
    – pick a random list element from the left items
    – redirect user to the selected random item

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

    #10916
    Avatar photofinrik

    In the “get-posts-by-tags.js” file there is now “random” as the value for sorting. But not yet in the documentation.

    There was nothing about this in the blog entry for the last version.

    In any case, thanks for that. Works perfectly for me. 👍

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