问题
I need to know how can I limit those post labels in blogger. I have searched out for it and could not find anything related to limiting post labels. This is what I have achieved so far.
NOTE: I want to show limited post labels under each post title. Like
if(post_label.count() < 3) { //show post label }
So, I need to show 3 labels under each post's title.
<div class='post-category'>
<span class='post-label'>
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label'>
<a expr:href='data:label.url + "?&max-results=10"' rel='tag'>
<data:label.name/>
</a>
<b:if cond='data:label.isLast != "true"'>
</b:if>
</b:loop>
</b:if>
</span>
</div>
回答1:
You can only do it by css, for example we have class "post-cat" :
<span class="post-cat">
<b:if cond='data:top.showPostLabels and data:post.labels'>
<b:loop values='data:post.labels' var='label'>
<a expr:href='data:label.url + "?&max-results=4"' rel='tag'>
<data:label.name/>
</a>
<b:if cond='not data:label.isLast'/>
</b:loop>
</b:if>
</span>
On css you can do this tip :
.post-cat a{
display: none;
}
.post-cat a:nth-child(1),
.post-cat a:nth-child(2),
.post-cat a:nth-child(3){
display: block;
}
I hope this helpful after 2 years ago of your question :)
回答2:
just replace max-results=3
with max-results=10
and save blogger template.
<a expr:href='data:label.url + "?&max-results=10"' rel='tag'>
you're required to change max-results=10
to limit specific "3" number of posts under each label in blogger.
回答3:
using <b:eval/>
tag it will be like
<b:eval expr="data:post.labels[0].name" />
<b:eval expr="data:post.labels[1].name" />
<b:eval expr="data:post.labels[2].name" />
or simply using this trick
<b:loop values='data:post.labels' index='i' var='label'>
<b:if cond='data:i == 1'>
<a expr:href='data:label.url' rel='tag'><data:label.name/></a>
</b:if>
</b:loop>
来源:https://stackoverflow.com/questions/23605073/blogger-how-to-limit-bloggers-post-label