1

Is there anyway I can limit entries within an entries tag. Not over all limit but within a particular column/row. If I have X amount of entries in a channel, I want them all to be displayed but only so many within a column. Please and thank you.

0
2

You can do something like that:

{exp:channel:entries
    channel="test"
    disable="categories|category_fields|member_data|pagination|trackbacks|relationships"
    dynamic="no"
}

    {if count%2 == 1}
    <div class="even">
    {/if}

    <p>{title}</p>

    {if count%2 == 0 || count == total_results}
    </div>
    {/if}

{/exp:channel:entries}
1

Mufaddal's answer will split the results into 2 columns. From your question I'm assuming you want the first X entries to be in a column, then the rest elsewhere...?

{exp:channel:entries
    channel="test"
    disable="categories|category_fields|member_data|pagination|trackbacks|relationships"
    dynamic="no"
    }

    {if count == 1}
        <div class="column">
    {/if}
    {if count == 6}
        </div>
        <div class="elsewhere">
    {/if}

    <p>{title}</p>

    {if count == total_results}
        </div>
    {/if}
{/exp:channel:entries}
0

Being X the number of columns you want, you can use the modulus operator:

{exp:channel:entries channel="news" limit="10"}
    {if count == 1 || count % X == 1}
        <div class="row">
    {/if}
            <div class="column">
                <h2>{title}</h2>
                {body}
            </div><!-- .column -->
    {if count == total_results || count % X == 0}
        </div><!--.row-->
    {/if}
{/exp:channel:entries}

The modulus will give you the remainder of a division of the count variable by the number of columns will want. In case the remainder is 1, the loop is starting a new row. In case it's 0, the loop is closing one.

Let's say you want 4 columns and a limit of 10, every new row will start at 5th and 9th iteration, being 1 the remainder of this positions by 4; and every row except of the last one will close at the 4th and 8th iterations, being their their remainders 0.

If you need to mark a last and incomplete row, you can use other mathematical operators at the first conditional:

    {if count == 1 || count % X == 1}
        <div class="row{if total_results - count < X} incomplete-row{/if}">
    {/if}

If the remainder is 1 and the difference between the count and the total_results variables is smaller than the number of columns you want, the row will be incomplete.

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.