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

xen foreach loop

Discussion in 'XenForo Development Discussions' started by gldtn, Feb 9, 2015.

  1. gldtn

    gldtn Well-Known Member

    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
     
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    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 likes this.
  3. Brogan

    Brogan XenForo Moderator Staff Member

    That code looks familiar ;)

    What are you doing exactly?
    Some sort of mini slider/carousel/?
     
  4. gldtn

    gldtn Well-Known Member

    It definitely did, it worked :D thanks for the help.

    I knew you would recognize it :p

    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: Feb 10, 2015

Share This Page