ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Put Entries in rows of 3 then add code

July 27, 2011 12:09pm

Subscribe [3]
  • #1 / Jul 27, 2011 12:09pm

    Shinetime Media

    8 posts

    I am having issues wrapping my head around an idea I have for a project.

    Here is the idea:

    I want to split up entries into rows of three and then have some extra code placed after each row. Then I want the process to continue until all the entries have been listed.

    Example:

    <div class=“row”>
    <div>Entry One</div>
    <div>Entry Two</div>
    <div>Entry Three</div>
    </div>

    <div>(extra content)</div>

    <div class=“row”>
    <div>Entry Four</div>
    <div>Entry Five</div>
    <div>Entry Six</div>
    </div>

    <div>(extra content)</div>

    ...and so on.

    This is probably a very simply process, but I can’t seemed to figure it out. Any help would be greatly appreciated.

    EE 2.2.1
    Build 20110705

  • #2 / Jul 27, 2011 4:20pm

    Adam Wiggall recently posted this solution to the same problem on Google+.  PHP would need to be enabled on your template in order for it to work, as it uses PHP…

    <?php $counter = 0; ?>
    
    {exp:entries tags}
    
    <?php $counter += 1; ?>
    <?php if ( $counter == 1 || $counter % 3 == 1 ): ?>
       <div class="row">
    <?php endif; ?>
    
          <div>Entry {count}</div>
    
    <?php if ( $counter % 3 == 0 || $counter == '{total_results}' ): ?>
       </div>
       <div>(extra content)</div>
    <?php endif; ?>
    {/exp:entries tags}
  • #3 / Jul 27, 2011 4:27pm

    Marcus Neto

    1005 posts

    Shinetime,

    Another option is to use the Switch parameter if you are doing this as part of an exp:channel:entries tag.

    Generally speaking to do something like what you are talking about you would do this:

    {switch='||<div>(extra content)</div>'}
  • #4 / Jul 27, 2011 4:57pm

    Switch will only throw that tag in after every third entry though.  If you have a situation with 8 entries instead of 9, the last <div>(extra content)</div> wouldn’t show up.  If that case isn’t a problem (in other words, if you know the number of entries shown will always be a multiple of 3), the switch parameter is probably a better / less complicated option.

  • #5 / Jul 27, 2011 9:56pm

    Shinetime Media

    8 posts

    Nick - Thanks so much man! That is exactly what I was looking for! You have officially put the final touches on a template for me… AND for that I really really thank you.

    Marcus, thanks as I can probably use switch in some other instances. This is an every growing channel in which the count won’t always be a multiple of three.

    Thanks again for all the help!

  • #6 / Jul 28, 2011 2:05pm

    Marcus Neto

    1005 posts

    Glad you got it sorted out.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases