Blogger: Como exibir apenas as postagens de um marcador (label) específico na homepage do blog?

Asked

Viewed 2,303 times

4

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

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

In the <b:section> main of the homepage, which is within the "div-1", are displayed normally all published posts, from the latest 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 be displayed ONLY posts with a marker specific, in this case "News".

For that 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 equal to the "div-1". Mesmo revisando o código não consegue visualizar onde está o erro que impede das postagens ser exibis APENAS com o marcador "News".

Any help is welcome, because this is all I need to finish the blog and I’ve been trying for days to solve this, without success.

  • Blogger is not a programming language, but a terminology referring to the site of discussion or information «1» «2», and are usually developed using several web languages, not one. Therefore, it would be good if this time you edited your question, not ignoring the tax title, but changing some or even all content related to blogger language. 'Cause then people can’t keep up with you.

  • Hi, Edilson, thanks for the observation. I wanted to formulate the question in the most specific way possible, but I ended up missing the classification of it as "blogger language". In fact, I tried to refer to Blogger’s "Page Elements Tags" as you describe this page: https://support.google.com/blogger/answer/46888?hl=pt-BR&ref_topic=12449 . I changed the title, leaving only the reference to the service name (Blogger), because if not the question can be ambiguous in relation to other blog services (Wordpress, Webnode, etc).

1 answer

3


I was able to find the solution!

The "div-2" code must have some conditional tag sequences <b:loop> which will serve to display the filtered posts according to the label (label) you want.

As stated in the question itself, the code to display all posts in the 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", to avoid conflict with the first div, the code below should be used:

DIV-2 (Only posts with label "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 from your blog, just replace the word "NEWS" in the code above with the word you prefer.

Thus, it will be possible to display on the same page of the homepage a section with the normal posts and another with the posts filtered by a certain category.

I hope this little answer will help other people with the same problem.

Thank you. You’re welcome!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.