<p>You can set an array and order them by random.</p>

<p><code>{% set gallery = craft.entries.section(['galleryA','galleryB','galleryC']) %}</code></p>

<p>Then you have to display them by random using <code>.order('RAND()')</code></p>

<p>So your <code>for loop</code> looks like:</p>

<p><code>{% for entry in craft.entries.section(gallery).order('RAND()') %}</code></p>

CC BY-SA 3.0
2017-03-14T07:55:19.780Z
2017-03-14T07:55:19.780Z
Justin Dekkers
<p>Rather than having separate entries, have you considered having one type of image but assigning <a href="https://craftcms.com/docs/categories" rel="nofollow noreferrer">categories</a> or <a href="https://craftcms.com/docs/tags" rel="nofollow noreferrer">tags</a> to them.</p>

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

<p><code>{% for entry in craft.entries.section('yourImageEntries').order('RAND()') %}</code></p>

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

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

{# Output them #}
{% for entry in entries %}
    &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Example taken from the official docs <a href="https://craftcms.com/support/entries-related-to-category" rel="nofollow noreferrer">here</a>.</p>

CC BY-SA 3.0
2017-03-14T07:56:12.653Z
2017-03-14T08:03:29.757Z
2017-03-14T08:03:29.757Z
Steve Holland
<p>I have looked around but cant find an answer to this.</p>

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

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

<p>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?</p>

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

CC BY-SA 3.0
2017-05-09T20:12:31.390Z
Hey Spheriri, could you please consider accepting either answer that helped you, or updating the question if it wasn't solved?
Matt Stein
<templating><ordering><responsive-images><gallery>
Another gallery question
# Another gallery question

(Asked by: username_0 on 2017-03-14)

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

**Tags:** templating, ordering, responsive-images, gallery
> **Comments:**
> **username_1**: Hey Spheriri, could you please consider accepting either answer that helped you, or updating the question if it wasn't solved?  

---

## 2 answers

### Answer by username_2 on 2017-03-14. Score: 1

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()') %}`


---

### Answer by username_3 on 2017-03-14. Score: 1

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 %}
    {{ entry.title }}
{% endfor %}

Example taken from the official docs here.


---

