Reputation: 29
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label'>
<data:label.name/>
,
</b:loop>
</b:if>
This loop lists all the labels in a post,
is it possible to limit the number of labels shown by controlling the loop (defining a loop count)?
Eg: There are total 7 labels in a post but i want only the first 3 to be displayed.
Upvotes: 3
Views: 2829
Reputation: 5651
It is possible to directly add the limit
keyword followed by the number to the values
field
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels limit 3' var='label'>
<data:label.name/>
,
</b:loop>
</b:if>
Upvotes: 2
Reputation: 101
Here is a simple solution :
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label' index='sth'>
<b:if cond='data:sth<3'>
<data:label.name/> ,
</b:if>
</b:loop>
</b:if>
In blogger :
<
= <
and >
= >
And I've used this statment : sth<3
Which means sth<3
, so that the loop will repeat 3 times, hence, 3 entries should show up (Because the loop starts from 0)
You could also create a range adding new statment as shown below :
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label' index='sth'>
<b:if cond='data:sth<6 and data:sth>2'>
<data:label.name/> ,
</b:if>
</b:loop>
</b:if>
The code above will show 3 labels picked up from the 3rd loop
to the 5th loop
.
Upvotes: 0
Reputation: 359
This one will show your first three labels (count starts from zero). 2 commas are also included, no comma for the third label.
<b:loop values='data:post.labels' var='label' index='x'>
<b:if cond='data:x <=2'>
<a class='sfa-tag' expr:href='data:label.url' rel='tag'>
<data:label.name/>
</a>
<b:if cond='data:x <=1'>,</b:if>
</b:if>
</b:loop>
Upvotes: 0
Reputation: 11
This works for me:
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label' index='x'>
<b:if cond='data:x==0'><data:label.name/>, </b:if>
<b:if cond='data:x==1'><data:label.name/>, </b:if>
<b:if cond='data:x==2'><data:label.name/></b:if>
</b:loop>
</b:if>
Or simply use <
or >
(encoded as <
and >
respectively):
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label' index='x'>
<b:if cond='data:x<=2'><data:label.name/>, </b:if>
</b:loop>
</b:if>
Upvotes: 1
Reputation: 3093
No, it is impossible to create new variable data and assign value to it in Blogger template XML. There is no documentation from Google that give information about it. Blogger template XML is not designed for it.
Upvotes: 0