Make 'shuffle' show different posts per post

I am using the code below to generate related posts. However, it shows the same six posts for all the posts. Is there a way to show different posts per post? (I used Latent Semantic Indexing in Jekyll to achieve the same. Not sure about Hugo)

{{ $filteredPosts := where (where site.RegularPages "Type" "post") "Title" "!=" .Title }}  
    {{ $relatedPosts := shuffle $filteredPosts | first 6 }}  
    {{ range $relatedPosts }}

Currently I don’t think that is possible (or: someone may come up with some trickery).

However, I recommend you have a look at this: Related Content | Hugo

Also see:

I had looked at that before asking but none works for my case.

Thanks for considering it. I will follow that topic when it is merged. When is the possible ETA for that version release? (Ideally, the random posts can be generated in every build as I don’t want to struggle looking for JS to do it. I want the posts generated and cached until the next build or I purge cache (I use Cloudflare Pages)

Edit: I even tried to remove shuffle but the first function returns the same posts, but the first five latest. The number should be somewhat of a limit of posts I want in the array. Thanks.

I am unable to reproduce this, so I’m probably doing something different. Have a look:

git clone --single-branch -b hugo-forum-topic-35900 https://github.com/jmooring/hugo-testing hugo-forum-topic-35900
cd hugo-forum-topic-35900
hugo server

I have noticed a change with my last build that the posts are now showing different. Figured out the problem was a partialCached I left on the single layout when including the related.html file.

OK, I probably misunderstood the original problem, but people have been asking for a custom seed to the shuffle func.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.