• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

xen foreach loop

gldtn

Well-known member
#1
How do I do a foreach loop up to only 5 items in a template?

This is what I have so far but I need to stop the loop after X amount of items
Code:
<div class="ctaSliderThumbs">
  <ul>
    <xen:foreach loop="$sliderEntries" value="$sliderEntry">
      <li class="avatar">
        <a href="{xen:link threads, {xen:string censor, $sliderEntry}}">
          <img src="{xen:helper featuredthreadsliderurl, $sliderEntry}"
            alt="{xen:string censor, $sliderEntry.featured_title}"
            width="50"
            height="50" />
        </a>
      </li>
    </xen:foreach>
  </ul>
</div>
Thanks
 

Nobita.Kun

Well-known member
#2
Code:
<xen:foreach loop="$sliderEntries" value="$sliderEntry" i="{$i}">
<xen:if is="{$i} < 5">
      <li class="avatar">
        <a href="{xen:link threads, {xen:string censor, $sliderEntry}}">
          <img src="{xen:helper featuredthreadsliderurl, $sliderEntry}"
            alt="{xen:string censor, $sliderEntry.featured_title}"
            width="50"
            height="50" />
        </a>
      </li>
</xen:if>
    </xen:foreach>
Its maybe help :)
 

gldtn

Well-known member
#4
It definitely did, it worked :D thanks for the help.

That code looks familiar ;)
I knew you would recognize it :p

What are you doing exactly?
Some sort of mini slider/carousel/?
Not quite, I actually wanted to change the default slider look with a smaller image and use thumbnails as the bx-pager. I was having a hard time because for some reason, it was pulling more items than I have on the slider. Also I can't seem to get the right link to get the slider to change with the custom pager/thumbs.

Can you shine a light please?

Here is what I have so far: http://cl.ly/image/2K1W3v3W0H2v
 
Last edited: