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

XF 1.5 Foreach loop

Lee

Well-known member
#1
I have this loop that i'm using in my heavily cutomised profile page. It selects every post to be submitted to the users profile. Is there a way to limit the amount of records selected?

<xen:foreach loop="$profilePosts" value="$profilePost"> </xen:foreach>
 

Chris D

XenForo developer
Staff member
#2
You can add an i attribute to the loop and each iteration will increment i by one:

Code:
<xen:foreach loop="$profilePosts" value="$profilePost" i="$i">
    <xen:if is="$i < 5">
         // Do something
    </xen:if>
</xen:foreach>
 

Chris D

XenForo developer
Staff member
#4
Sorry:

Code:
<xen:foreach loop="$profilePosts" value="$profilePost" i="$i">
    <xen:if is="{$i} < 5">
         // Do something
    </xen:if>
</xen:foreach>