Blogger - How to limit blogger's post label

霸气de小男生 提交于 2020-01-30 12:55:23

问题


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 + &quot;?&amp;max-results=10&quot;' rel='tag'>
                    <data:label.name/>
                </a>
                <b:if cond='data:label.isLast != &quot;true&quot;'> 
                </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 + &quot;?&amp;max-results=4&quot;' 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 + &quot;?&amp;max-results=10&quot;' 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!