How to show a list of random posts

As Hugo is a static site generator, you’ll need to handle that with JavaScript.

Perhaps your list page contains summaries of all of your posts, each within a <div id="n" class="summary">, where n is a sequential number ranging from 1 to the number of posts. Set the CSS for div.summary to display: none initially.

Then have JavaScript generate a list of 5 random numbers between 1 and the number of posts. Then iterate through the list, setting the style for div#n.summary to display: block.

1 Like