Streaming live at 10am (PST)

Show random blog post on each page load


#1

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?


#2

HI @Jiyu,

Let’s say you have 10 post and you want 2 random post to appear.
You need to limit item like so

58

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)


#3

You can do a random from a list (e.g.: 10) using custom code. Means you load 10 but display a random 1.


#4

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.


#5

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.


#6

@zbrah @Jiyu

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.


#7

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?


#8

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,


#9

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


#10

Hey @zbrah @Thuu_Phan

The 24h time frame for displaying random collection items hasn’t changed :slight_smile:


#11

@zbrah

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. :grimacing:


#12

I think it’s multiple time in the designer @magicmark yes, it does that only on published.


#13

@samliew So once I set the limit and display to none, what kind of custom code can I use to display a random?


#14

Link to published page?


#15

http://pointman-v2.webflow.io/ - It’s the hero section they wanted implemented into a CMS - there’s only 4 hero versions


#16

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.


#17

Okay sorry, try now - it hides the whole thing so I wasnt sure if you needed to see it or not! :slight_smile:


#18

Paste in Page Footer Code:

<script>
var items = $('.hero-item');
items.eq(Math.floor(Math.random() * items.length)).show();
</script>

#19

Thanks!! You’re the best!