Search code examples
content-management-systemexpressionengine

Expression Engine: split entries into groups


Quick question: How can I output all entries from a given channel into groups of 4, like so:

<div class="entry_group">
    <div class="entry" id="1"><span>{title}</span></div>
    <div class="entry" id="2"><span>{title}</span></div>
    <div class="entry" id="3"><span>{title}</span></div>
    <div class="entry" id="4"><span>{title}</span></div>
</div>
<div class="entry_group">
    <div class="entry" id="5"><span>{title}</span></div>
    <div class="entry" id="6"><span>{title}</span></div>
    <div class="entry" id="7"><span>{title}</span></div>
    <div class="entry" id="8"><span>{title}</span></div>
</div>

Thanks in advance!


Solution

  • You can try using the Modulo Operator plugin to acheive this with any number of entries. Something like this:

    {if count == "1"}
        <div class="entry_group">
    {/if}
    {if '{exp:modulo dividend="{count}" divisor="4"}' == 0}
        </div>
        <div class="entry_group">
    {/if}
            <div class="entry" id="{count}"><span>{title}</span></div>
    {if count == total_results}
        </div>
    {/if}
    

    The plugin is for EE1 only, but converting a plugin from EE1 to EE2 is a breeze.