开发者

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"><spa开发者_运维技巧n>{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!


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.


I found another, much simpler solution on the ExpressionEngine forums; while fairly basic I think it should accomplish the desired goal fairly easily: http://expressionengine.com/forums/viewthread/197240/#927740

The jist of it involves using the {switch} variable to optionally insert closing and opening tag pairs after every n group of entries, depending on how many blank spots you leave in the switch. In your case, the example would be something like this:

<div class="entry_group">
{exp:channel:entries}
    <div class="entry" id="{switch='1|2|3|4'}"><span>{title}</span></div>
    {switch='|||</div><div class="entry_group">'}
{exp:channel:entries}
</div>

The whitespace between the div and class=entry_group shouldn't cause any issues, but if it does you may want to use CSS to control the properties of the containers without having to put a class on them (e.g. .entry_list>div{... and .entry_list>div .entry{...


I did find a semi-solution on the Expression Engine forums, but it requires a limit on the total number of entries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜