Blogger: How can I display only the posts of a specific label on the blog homepage?

2

I am facing serious difficulties in solving a problem in creating a template that should be simple to solve, but it is already consuming me a lot of time without reaching a solution.

It happens that I created a XHTML Strict template from scratch to use in a blog with two standard DIVs (id="div-1" and id="div-2") in the form of two columns that occupy, 50% of the screen.

In the% main% of the homepage, which is within "div-1", all published posts are displayed normally, from the most recent to the oldest. For this, I used the following code:

<div id="div-1">
<b:section id='main'>
    <b:widget id='Blog1' locked='true' title='Todas as postagens' type='Blog'>
    </b:widget>
</b:section>
<div>

So far so good. It turns out that in "div-2", I want to ONLY display the posts with a specific tag , in this case "News".

For this I tried to use the following code:

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

  <b:includable id='main2'>
    <b:if cond='data:label.name == &quot;Notícias&quot;'>
    <data:content/>
    </b:if>
  </b:includable>

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

The above code even displays the posts, but just like "div-1". Even by reviewing the code I can not see where the error is that prevents the posts from being displayed ONLY with the bullet "News".

Any help is welcome, because all that is missing is for me to finish the blog and I've been trying to solve this for days without success.

    
asked by anonymous 31.10.2015 / 20:37

1 answer

2

I was able to find the solution!

The code for "div-2" should have some conditional sequences of <b:loop> tags that will serve to display the filtered posts according to the label you want.

As discussed in the question itself, the code to display all posts in a normal way should be:

DIV-1 (All posts)

<div id="div-1">
<b:section id='main'>
    <b:widget id='Blog1' locked='true' title='Todas as postagens' type='Blog'>
    </b:widget>
</b:section>
<div>

In "div-2", in order not to conflict with the first div, use the following code:

DIV-2 (Only posts marked "NEWS")

<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>

If you want to include a custom bookmark for your blog, simply replace the word "NEWS" in the above code with the word you prefer.

This will allow you to display a section with normal posts on the same page as the homepage, and another with the posts filtered by a certain category.

I hope this little answer can help others with the same problem.

Thank you. You're welcome!

    
01.11.2015 / 01:25