1

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?

1 Answer 1

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 %}
1
  • Thanks for the fast answer, Carlos. Will try that right away. Commented Dec 10, 2015 at 16:27

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.