Random content is a great way to simulate activity on your site. Especially the homepage is a perfect place to show randomly selected articles from your blog, a different header image each time the page gets refreshed or a box with a random featured project from your portfolio.
There are multiple ways to use this technique to create more life on your site even if you don't update it very often and it gives you the chance to promote older content, which might already be burried deep down below newer stuff.
Kirby has a built-in method to sort pages randomly. You can use that for any set of pages. Here are some examples:
You can even get a defined set of pages by URI and shuffle that.
Sorting a set of pages randomly will still return the entire set of pages of course. So if we only need one or just a few random pages for our homepage for example, we have to limit the result afterwards. There are two ways to do it:
If we need two, three or more featured projects, we can do it like this:
So with those simple methods we can easily get any random content from our site.
Random content is cool, but random images are even cooler. Think about random background or header images, shuffled galleries and stuff like that. There's so much you can do with it. The method to fetch random images is exactly the same as fetching random content.
If you are building a template for the homepage and you need to get random images from any page of your site, you can do it like this:
You could even get a random image from a random page: