htmlxmlbloggerblogger-dynamic-views

Limit the number of posts per tag on Blogger


I have this code that displays posts by tag on the blogger.

Would anyone know help me format it so that it only displays 4 posts?

The Code searches the blogger XML for existing posts but only displays those that contain the tag specified in the code.

 <div id="div-2">
    <b:section id='posts-noticias'>
    <b:widget id='Blog2' locked='true' title='Blog Archive' type='Blog'>

    <b:includable id='main' var='top'>
        <b:loop values='data:posts' var='post'>
        <b:if cond='data:blog.url == data:blog.homepageUrl'>
        <b:if cond='data:post.labels'>
        <b:loop values='data:post.labels' var='label'>
        <b:if cond='data:label.name == "NOTÍCIAS"'>
        <b:include data='post' name='printPosts'/>
        </b:if>
        </b:loop>
        </b:if>
        <b:else/>
        <b:include data='post' name='printPosts'/>
        </b:if>
        </b:loop>
    </b:includable>

    <b:includable id='printPosts' var='post'>
        <b:if cond='data:post.dateHeader'>
        <h2 class='date-header'>
        <data:post.dateHeader/>
        </h2>
        </b:if>
        <b:include data='post' name='post'/>
        <b:if cond='data:blog.pageType == &quot;static_page&quot;'>
        <b:include data='post' name='comments'/>
        </b:if>
        <b:if cond='data:blog.pageType == "item"'>
        <b:include data='post' name='comments'/>
        </b:if>
    </b:includable>

</b:widget>
</b:section>

Solution

  • <b:includable id='main' var='top'>
      <b:if cond='data:view.isHomepage'>
        <b:loop values='data:posts where (p=> p.labels any (l=> l.name == "NOTÍCIAS")) take 4' var='post'>
          <b:include data='post' name='printPosts'/>
        </b:loop>
        <b:else/>
          <b:loop values='data:posts' var='post'>
            <b:include data='post' name='printPosts'/>
          </b:loop>
      </b:if>
    </b:includable>