Blogger: Filter posts by label on your main page

I spent quit a while phishing around google trying to figure out how to prevent posts with a certain label from appearing on my main page over at blogger/blogspot. Eventually, I used an adaptation of this method (also detailed here).

To applay this method, edit your blogger sites XML template (be sure to back it up first!), and click "Expand Widget Templates". Now look for the line:

<b:loop values='data:posts' var='post'>

And find the matching </b:loop> tag.

Replace them and everything between them with the following code:

<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.isLast == &quot;true&quot;'>
<b:if cond='data:label.name != "Label_To_Filter">
<b:include data='post' name='printPosts'/>
</b:if>
</b:if>
</b:loop>
</b:if>
<b:else/>
<b:include data='post' name='printPosts'/>
</b:if>
</b:loop>

Now look for the last </b:includable> tag you can find, and paste this code directly after it:

<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 == "item"'>
<b:include data='post' name='comments'/>
</b:if>
</b:includable>

Note that this code has a few bugs:

  1. Posts with no label will not be displayed on the main page.

  2. The filtered label must be the last label of a filtered post.

  3. If all your recent stories belong to the filtered category, your blog may appear empty.


I consider these "Features" as they suit my need over at www.luxphile.com - preventing any of my Texture labeled posts from showing up on the main page, and also hiding unlabeled "Blog this" posts from Flickr.