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.

Looping through results

August 27, 2012 1:04pm

Subscribe [2]
  • #1 / Aug 27, 2012 1:04pm

    kev_horan

    50 posts

    Hi there,

    Im trying to find a more elegant way to do the below - with php most likely. Im displaying my results in a royalslider, 9 entries per slide. I’d prefer not to avoid the hard coded approach below, so I was trying to find a way to iterate a variable and reset it every 9 results, but I wasnt having much luck.

    Any insight/help would be much appreciated.

    Kevin

    {exp:channel:entries channel="channel_name" limit="90" sort="asc" disable="member_data|trackbacks"}                          
    {if count == '1' OR count == '10' OR count == '19' OR count == '28' OR count == '37' OR count == '46' OR count == '55' OR count == '64' OR count == '73' OR count == '82' }
         <li class="royalSlide"> 
                <div class="centeredSlide clearfix">
    {/if}         
                 <div class="item">             
                  <a href="http://{path=lorem/ipsum/detail/{url_title}}">_{exp:ce_img:pair src="{preview_image:url}" width="116" height="110" crop="yes"}{made}{/exp:ce_img:pair}_              </a>
                  <div class="copy">
                   {media_type}
                   <h4><a href="http://{path=lorem/ipsum/detail/{url_title}}">{title} <?php echo($read_count); ?></a></h4>
    <p>              </div> <br />
                 </div>  <br />
    {if count == '9' OR count == '18' OR count == '27' OR count == '36' OR count == '45' OR count == '54' OR count == '63' OR count == '72' OR count == '82' OR count == '90' }<br />
                   </div><br />
               </li><br />
    {if:elseif count == total_results}           <br />
                   </div><br />
               </li><br />
    {/if}

  • #2 / Aug 27, 2012 1:29pm

    John St-Amand

    865 posts

    Switch variable to the rescue:

    {exp:channel:entries channel="channel_name" limit="90" sort="asc" disable="member_data|trackbacks"}
    {!-- open royalSlide at the beginning of each grouping of 9 entries --}                   
    {switch="<li class='royalSlide'><div class='centeredSlide clearfix'>||||||||"}
          
                 <div class="item">             
                  <a href="http://{path=lorem/ipsum/detail/{url_title}}">_{exp:ce_img:pair src="{preview_image:url}" width="116" height="110" crop="yes"}{made}{/exp:ce_img:pair}_              </a>
                  <div class="copy">
                   {media_type}
                   <h4><a href="http://{path=lorem/ipsum/detail/{url_title}}">{title} <?php echo($read_count); ?></a></h4>
    <p>              </div> <br />
                 </div>  <br />
    {!-- close royalSlide at the END of each grouping of 9 entries --}<br />
    {if count != total_results}{switch="||||||||</div></li>{!-- /close after each 9 entries --}"}{/if}<br />
    {!-- in the event that the last grouping did not end on an even 9 entries, we close the loop here after the last entry --}<br />
    {if count == total_results}</div></li>{/if}

    I believe that should work for you, no PHP needed.

  • #3 / Aug 27, 2012 2:43pm

    kev_horan

    50 posts

    Thanks John - thats perfect. Much appreciated…

  • #4 / Aug 27, 2012 2:47pm

    John St-Amand

    865 posts

    You’re very welcome.  The switch variable is so often used for doing nothing more than dropping in a CSS class or something that uses like this are often forgotten.

    Cheers.

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

ExpressionEngine News!

#eecms, #events, #releases