2

First time here so excuse me if I get the etiquette and protocols wrong.

I am trying to pull eight featured stories into a page, the first two into a large two column grid and the rest into a three column grid. Try as I may I can not get this to work... I have searched around here for various solutions but none seem to be exactly what I am trying to achieve, or I have the know how to adapt.

I am trying to exclude the first two entries from the second section but want the whole display to be random. I am guessing the array string of ids() is not being parsed or set up correctly but frankly I am a bit lost so any help would be very much appreciated.

So far I think this is the closest I have come.

<div class="row small-up-1 medium-up-2">
    {% set featuredStories = craft.entries.section('work').type('projects') %}
    {% set big = featuredStories.order('RAND()').limit(2) %}

    {% for entry in big %}
        <— stuff —>
    {% endfor %}
</div>

{% set bigIds = big.ids() %}
{% set bigIdsString = bigIds | join(', not ') %}

{% set allEntries = featuredStories.id('and, not '~bigIdsString) %}

<div class="row small-up-2 medium-up-3">
    {% for entry in allEntries %}
        <— stuff —>
    {% endfor %}
</div>
  • Welcome, @TheOldDesigner! Perfect form on your first question, so naturally we all expect great things. :) – Matt Stein Jul 4 '17 at 17:19
1

I'd probably try is something like this:

<div class="row small-up-1 medium-up-2">
    {# Grab all (8) stories in a random order #}
    {% set allStories = craft.entries.section('work').type('projects').order('RAND()').find() %}

    {# Now loop through only the first two items in the array #}
    {% for entry in allStories|slice(0, 2) %}
        <— stuff —>
    {% endfor %}
</div>

<div class="row small-up-2 medium-up-3">
    {# Now loop through items 3-8 in the array. #}
    {% for entry in allStories|slice(2, 6) %}
        <— stuff —>
    {% endfor %}
</div>

Documentation for the Twig slice() method can be found here: https://twig.sensiolabs.org/doc/2.x/filters/slice.html

  • Thank you that worked perfectly, I had not looked at slice, much appreciated! – The Old Designer Jun 30 '17 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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