<p>I would just <a href="http://twig.sensiolabs.org/doc/filters/slice.html" rel="nofollow"><code>slice</code></a> the randomized array of categories:</p>

<pre><code>{% set ads = craft.categories({
    group: 'ads',
    order: 'RAND()'
}) %}

{% for ad in ads|slice(0, 2) %}
    {{ ad.externalUrl }}
{% endfor %}

{% for ad in ads|slice(2, 4) %}
    {{ ad.externalUrl }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-12-10T16:27:53.993Z
Thanks for the fast answer, Carlos. Will try that right away.
Markus Busch
CC BY-SA 3.0
2015-12-10T15:35:12.463Z
2015-12-10T15:35:12.463Z
carlcs
<p>I have created 12 sponsorship ads for my website using a “sponsor” category.</p>

<p>On my home page I have four sponsorship sections, each holding three sponsorship ads.</p>

<p>How can I randomly distribute those 12 sponsorship ads among the four sponsorship areas with each homepage load?</p>

<templating>
Randomly listing entries in more then one section
# Randomly listing entries in more then one section

(Asked by: username_0 on 2015-12-10)

I have created 12 sponsorship ads for my website using a “sponsor” category.

On my home page I have four sponsorship sections, each holding three sponsorship ads.

How can I randomly distribute those 12 sponsorship ads among the four sponsorship areas with each homepage load?

**Tags:** templating


---

## 1 answers

### Answer by username_1 on 2015-12-10. Score: 1

I would just slice the randomized array of categories:
{% set ads = craft.categories({
    group: 'ads',
    order: 'RAND()'
}) %}

{% for ad in ads|slice(0, 2) %}
    {{ ad.externalUrl }}
{% endfor %}

{% for ad in ads|slice(2, 4) %}
    {{ ad.externalUrl }}
{% endfor %}

> **Comments:**
> **username_0**: Thanks for the fast answer, Carlos. Will try that right away.  

---

