I have looked around but cant find an answer to this.

I have a structure for my gallery page, in-which there are three separate entries called A, B and C.

There are different images within these entries. But how would I go about showing all the images within these entries in a random order?

Say I went to the gallery page and they all showed up randomly, then theres a sub navigation to the separate entries on there own?

It's probably a simple solution but templating it has me really confused. Thank you

  • Hey Spheriri, could you please consider accepting either answer that helped you, or updating the question if it wasn't solved?
    – Matt Stein
    Commented May 9, 2017 at 20:12

2 Answers 2


You can set an array and order them by random.

{% set gallery = craft.entries.section(['galleryA','galleryB','galleryC']) %}

Then you have to display them by random using .order('RAND()')

So your for loop looks like:

{% for entry in craft.entries.section(gallery).order('RAND()') %}


Rather than having separate entries, have you considered having one type of image but assigning categories or tags to them.

That way you could output your images in a random order using .order('RAND()') on the end of your for loop. Something like this:

{% for entry in craft.entries.section('yourImageEntries').order('RAND()') %}

Then if you want to output your images by specific category you can do it like this:

{# Fetch all of the entries related to this category #}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}

Example taken from the official docs here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.