I’d like to know if (and how) I could use Webflow to show one random blog post on a page, each time the page loads?
And if so, what would be the “best” way to do it, do you think?
I’d like to know if (and how) I could use Webflow to show one random blog post on a page, each time the page loads?
And if so, what would be the “best” way to do it, do you think?
HI @Jiyu,
Let’s say you have 10 post and you want 2 random post to appear.
You need to limit item like so
And then sort order to random order
If you wan’t a instant new random after refresh, that’s not possible with webflow.
It takes 24 hours to create a new random (From my understanding, it’s due to flat publishes and CDN fastly)
You can do a random from a list (e.g.: 10) using custom code. Means you load 10 but display a random 1.
This sounds promising… How would I go about doing so, if you don’t mind me asking?
Do you mean that I create a Collection of blog posts, then show collection in a div/section, limit display to 1 post and then have it set to random?
Maybe I misinterpreted what you’re meaning? What kind of custom code are you thinking of and where would I put it?
Thanks for your time answering me.
No, means you limit to 10, hide all of them (set to display none), then use custom code to display a random.
You’ll have to do the first step then get back to me.
I use this site twice a year with random shuffle on the Collection list, and it seems to shuffle on refresh. No exhibitor then gets preferential treatment. Another site has one advert each page and that also changes upon refresh.
Do you mean that I create a Collection of blog posts, then show collection in a div/section, limit display to 1 post and then have it set to random?
Hey @magicmark, you mean on the home page ?
Doesn’t shuffle for me on refresh, even with the no cache refresh.
Hey @Brando how are you dude ?
Do you know if the 24h hours refresh time for shuffle changed ?
Thanks,
HI @Thuu_Phan, i’m not sure who you are asking to but if it’s to me :
When you want to do random on post for example, most of the time it’s because you want at the end of a post let’s say 3 post showing randomly.
That’s why i talk about limit item as a first step.
Let’s say you have 100 post.
If you limit to 3, only 3 block post are going to appear at the end of pour blog post.
If you add a random, then 3 different posts out of the 100 posts are going to display in those block every 24h.
Hope this helps
Hey @zbrah @Thuu_Phan
The 24h time frame for displaying random collection items hasn’t changed
Sorry, my mistake. I thought it refreshed more often than that on the Wedding website… does it re-sort multiple times when in the designer, or still the 24hrs?
As for the advert on different pages, it’s a different collection list on each static page so they act independently from each other, which is not the same thing as was asked of the OP.
I think it’s multiple time in the designer @magicmark yes, it does that only on published.
@samliew So once I set the limit and display to none, what kind of custom code can I use to display a random?
Link to published page?
http://pointman-v2.webflow.io/ - It’s the hero section they wanted implemented into a CMS - there’s only 4 hero versions
It seems that there is only one item in the list, you’ll have to remove all the limits, and hide the dyn-item itself.
Okay sorry, try now - it hides the whole thing so I wasnt sure if you needed to see it or not!
Paste in Page Footer Code:
<script>
var items = $('.hero-item');
items.eq(Math.floor(Math.random() * items.length)).show();
</script>
Thanks!! You’re the best!
Hey Samliew, I have a similar situation but want to know if I copy your script, would I change .hero-item to which element in my setup? I have a slider displaying cms testimonials, would I change it the wrapper item ?
Thx