41 How To Filter Posts by Label on the Home Page (Create a Side-Blog)
September 26, 2008 /

Some of my favorite (non-Blogger) blogs display a "sideblog" in their layout in which to display news snippets and links to interesting sites. These sideblog entries (often called "asides" or "link blogs") are much shorter than a regular blog post, and do not appear in the regular posts section.

While it would be simple to create a sideblog using a links list widget, Twitter, or by adding a Del.icio.us RSS feed to the sidebar, such methods would not allow readers to leave comments on our blogs about these entries. To allow commentary for sideblog entries, they need to be regular blog posts in a category whose posts are filtered from the front page.

In this post, I'll explain how you can filter posts of a particular label from being displayed on your blog's homepage then use this label's feed to display your sideblog.


Step 1: Back-up your template!

Before making any changes to your Blogger template, it is always good practice to make a back-up of your existing template. It is especially important for this Blogger hack: we will be filtering which posts display on the homepage, and any errors could result in no posts being displayed at all!

To back up your Blogger template, go to Layout>Edit HTML in your Blogger dashboard, and click the "Download full template" link near the top of the page.

You will then be prompted to save your template as a file to your computer hard drive which you could use to restore your template (if you make a mistake) or revert back if you change your mind about using this hack.

Step 2: Editing the posts loop

First, go to Layout>Edit HTML in your Blogger dashboard, and ensure you have checked the "Expand widget templates" box.

The code which we need to edit is located within the "Blog Posts" widget.

Finding the correct section of your template to edit can be a little tricky, as there are several elements which at first glance appear to utilize similar code. Here is the section which we need to edit:


  <!-- posts -->
  <div class='blog-posts hfeed'>

    <b:include data='top' name='status-message'/>

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

      <b:if cond='data:post.dateHeader'>
        <h4 class='date-header'><data:post.dateHeader/></h4>
      </b:if>
      <b:include data='post' name='post'/>
      <b:if cond='data:blog.pageType == "item"'>
<b:include data='post' name='comments'/>
<b:include data='post' name='comment-form'/>
 <div id='backlinks-container'>
    <div expr:id='data:widget.instanceId + "_backlinks-container"'>
       <b:if cond='data:post.showBacklinks'>
         <b:include data='post' name='backlinks'/>
       </b:if>
    </div>

In your own template, this code may not contain the <data:adStart/> and <data:adEnd/> tags, though this should not affect the overall functionality of this customization.

If you struggle to locate this section of code, use your browser's search function to locate the following phrase: hfeed which should be present no matter which template you are using.

When you have located this section of code (or similar), replace it with the following instead:


  <!-- posts -->
  <div class='blog-posts hfeed'>

    <b:include data='top' name='status-message'/>

    <data:adStart/>
  <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 == "true"'>
        <b:if cond='data:label.name != "Sideblog"'>
      <b:include data='post' name='post'/>
      <b:if cond='data:blog.pageType == "item"'>
        <b:include data='post' name='comments'/>
      </b:if>
      <b:if cond='data:post.includeAd'>
        <data:adEnd/>
        <data:adCode/>
        <data:adStart/>
      </b:if>
      </b:if>
      </b:if>
      </b:loop>
    </b:if>
</b:if>
  </b:loop>
    <data:adEnd/>
  </div>
Be sure to highlight all of the code and replace with the section above in its' entirety! Otherwise, when you attempt to preview or save this code, you will receive errors saying that tags are not closed properly.

In the code above, you will notice I have highlighted "Sideblog" in bold red. This is the name of the label which we will be filtering from the display of posts on the home page. You can change this to any label name you prefer. This is case sensitive, so be sure to use the same case in the code as the label you will use to tag your posts (ie: "Sideblog" is not the same as "sideblog").

Once you have edited this section of code, attempt to preview your template. If any of your recent posts have already been tagged with the "Sideblog" label, you will now notice they are missing from the output of posts.

Provided there are no errors visible when you preview your template, you can now save your edited template.


Step 3: Adding a feed widget to display your sideblog

Now we have filtered "Sideblog" posts from the list of recent posts on the home page, we need to add a widget to display sideblog posts in the sidebar.

To achieve this, we will use the sideblog label feed.

All Blogger blogs which use labels produce a feed of posts from each label. The URL for label feeds appears like this:

http://yourblog.blogspot.com/feeds/posts/default/-/LabelName

Where "LabelName" is the name of the particular label you wish to use.

This URL structure also works for custom domains. Simply replace "yourblog.blogspot.com" with the main URL for your blog.

In this example, we will use "Sideblog" for the name of the label in the feed, which would look like this:

http://yourblog.blogspot.com/feeds/posts/default/-/Sideblog

Using Feedburner to display sideblog posts

The simplest way to display your sideblog is to burn your label feed through Feedburner, and use the BuzzBoost widget code within an HTML/JavaScript widget.

To do this, go to Feedburner.com and add the URL of your label feed. Then go to Publicize>BuzzBoost in the dashboard for this new feed.

The code required to display your sideblog posts as HTML will be generated for you automatically which you can paste in an HTML/JavaScript widget in the Page Elements section of your blog. Alternatively, you could add this as a widget automatically using the widget installer option.

Using a regular Feed widget to display your sideblog

If you prefer not to use Feedburner, it is possible to display your sideblog using a regular feed widget. However, this will require more editing of your blog's HTML code (as Feed widgets will only display the post titles by default).

Here is how to use a Feed widget to display post summaries for a sideblog in Blogger:
  1. Go to Layout>edit HTML in your blog dashboard. Do not check the "Expand widget templates" box.
  2. Find the following line of code (or similar) in your template:

    <b:section class='sidebar' id='sidebar'>
    Depending on your template, the code may not appear using the exact same phrases. If you are at all confused, search for a familiar widget title instead. 
  3. Immediately after this line of code, paste the following in it's entirety:

    <b:widget id='Feed99' locked='false' title='Blogger Buster' type='Feed'>
    <b:includable id='main'>
    <h2><data:title/></h2>
    <div class='widget-content'>
    <b:loop values='data:feedData.items' var='i'>
    <h3><span class='item-title'>
    <a expr:href='data:i.alternate.href'>
    <data:i.title/>
    </a>
    </span></h3>
    <div><data:i.summary/></div>
    <b:if cond='data:showItemDate'>
    <b:if cond='data:i.str_published != &quot;&quot;'>
    <span class='item-date'>
    <p><data:i.str_published/></p>
    </span>
    </b:if>
    </b:if>
    <b:if cond='data:showItemAuthor'>
    <b:if cond='data:i.author != &quot;&quot;'>
    <span class='item-author'>
    <p><data:i.author/></p>
    </span>
    </b:if>
    </b:if>
    </b:loop>
    <b:include name='quickedit'/>
    </div>
    </b:includable>
    </b:widget>
  4. Now preview your template. If you have followed the steps correctly, you will receive no errors when you preview your template and should proceed to save. If you do receive errors, click the "Clear edits" button and begin again, being careful to paste the code after the <b:section> line.
  5. Once you have saved, go to Layout>Page Elements in your Blogger dashboard. Click on the edit link for the new feed widget you have added.
  6. In the "Feed URL" section, add the URL for your "Sideblog" label feed (see instructions above to locate this URL). In the preview, you will see each item title appear in a bulleted list. This is fine and perfectly normal. Save the feed widget here.
  7. Now when you take a look at your blog, you will see your "Sideblog" feed displays post titles and a short summary of each sideblog entry in the sidebar.

Once you have added your widget and configured the feed URL, you should be able to move the location of your sideblog through the "Page Elements" section of your dashboard.

Here is an example of how your new sideblog could appear:



Using your new sideblog

In order to use your newly added sideblog effectively, there are a couple of things which you ought to be aware of. I'll explain all of these "caveats" to ensure you can make use your sideblog to the full potential.


Sideblog entries should only be labeled with the "Sideblog" label!

When writing a sideblog post, be sure you only add the "Sideblog" label (or the name you chose when adding this function to your template). This label will be case sensitive, so "sideblog" and "Sideblog" will appear as two different labels.

If you do add more than one label to your sideblog posts, these posts will also appear in the main posts column, alongside your regular blog posts.


Sideblog images should be sized to fit their container

This one may be a little more tricky.

You can use images in your sideblog posts. However, you should ensure they are no wider than your sidebar (or the widget area they are contained in).

For example, if your image is 400px wide, being displayed in a sideblog whose width is only 200px, you will notice one of two things:
  • The right-hand edge will be truncated (in Firefox and other browsers)
  • The sidebar is pushed beneath the posts column (in IE)
Wherever possible, ensure you use the "small" size option for your image when uploading. Try also to ensure your image is centered above the text, as left or right aligned images may cause layout problems, especially when displayed in the sidebar/other narrow widget area.


Images detract from the length of the summary

When you display an image in your sideblog posts, the HTML code for the image is counted towards the text count of the summary, thus shortening the amount of text which will be displayed. If you prefer to display more text, be sure to place images at the bottom of your posts so these will only be displayed on item pages (not in your sidebar).


Using this filtering function for other template features

In this tutorial, I have explained one possible use for the filtering of posts by label: how to create a sideblog.

Those of you who actively design or develop Blogger templates may already see the possibilities of using this function for possibilities like:
  • A "Featured posts" section
  • A magazine style layout, where recent posts are organized by category on the home page
  • Only one category of post to be displayed on the home page (the rest organized by label and accessible through sidebar links).
From my own experiences, I assure you that all of these uses are possible in Blogger templates (though their respective tutorials would each be as long as this one!). So if you are confident in customizing your Blogger template code, I urge you to experiment with this tutorial to create a layout style appropriate for your needs :)

I hope you have enjoyed reading about filtering posts by label in this tutorial, and now have the knowledge required to add asides in your own Blogger template. Please let me know your thoughts and opinions by leaving a comment below.

41 Comments:

26 September 2008 20:13 indungg said...

Oh,..Great tips amanda...!
Thanks.

26 September 2008 21:20 dcloud said...

I wrote an article on using BuzzBoost...

http://www.dcblog.net/2008/09/display-your-recent-posts-via-buzzboost.html

...and also how to create a content box to put it in.

http://www.dcblog.net/2008/09/box-up-your-buzzboost.html

26 September 2008 22:34 subagya said...

yai... great i like this.... nice amanda

26 September 2008 22:35 mangel said...

very, very interesting post

26 September 2008 23:34 agus mu said...

it gives me a great idea!!!

27 September 2008 03:03 Design collective said...

wow: i have read post

Design24h.com

27 September 2008 05:36 Rev. Jeremy Smith said...

Amanda, it's not explicit in your post, but I assume this will have no effect on RSS readers and they will see the sideblog posts in the normal feed...right?

28 September 2008 03:30 Dunia Blogger said...

OK I like this, i want to tray... thanks...

28 September 2008 07:19 PALS said...

Thanks amanda

30 September 2008 02:00 Tinh said...

Great guidelines, I would give it a try and tell you if any problems happen :-)

1 October 2008 00:33 tabuhan said...

Thank You Amanda :]

1 October 2008 04:51 FriedClyde said...

Theres a huge gap where the content of your page ends and the to the top icon, around two pages of blank screen.

I use opera Amanda, cheers.

3 October 2008 21:46 Muhammad Yaqoob said...

very informative blog. it helps.
keep it up.

9 October 2008 15:46
Hackberry said...

Great blog...

i tried to implement the sideblog as instructed, but when i paste the above code in my template my blog posts disappears.

Think you could help me with that?

my test blogg http://mybloggname.blogspot.com/

15 October 2008 02:10 sexy said...

nice tutorial
http://bloggerfriendster.com

21 October 2008 17:05 POOJA said...

Hellow
Amanda

Few Months Back i Hv View yrs template sidebar a widget that reflect post headline with image and are changing in every second .
Will you give us that trick on how you do that i would like to use that trick for my fntblog ,For This i am also very thankful to you, and think many bllogger are searching 4 dis also.

Thanks
Reply
Link -http://fntblog.blogspot.com

26 October 2008 02:36 Cole said...

This is a great idea. It might be something I implement to show the most recent site updates which tend to get lost in the rest of my posts.

30 October 2008 04:49 ARCHITECT said...

hi AManda,

I tried this one, but the problem is, Its the main post that has the "categorized" feed. HOw can I make the "sideblog" that has the "categorized feed. Thanks

Please specify where to put the "feed URL" that might be the one that Im doing wrong. Thanks

13 November 2008 04:57 Ir. hydir said...

Good day ... I have the same problem as Hackerberry comments on 9/10/08

i tried to implement the sideblog as instructed, but when i paste the above code in my template my blog posts disappears.

Think you could help me with that?

when I see my post is missing.. I stop and return to my existing template ..

for your info .. I'm also using breadcrumb trail ...is it the root cause of the problem?

20 November 2008 13:21 poton said...

hi..i wanna knw how to create different categories in a blog archive field..like i want to create categories of games, music, movies etc..and put articles related to games in games category and similarly other articles in related fields...i m using blogspot account.....can u help me??

19 December 2008 02:53
Anonymous said...

hi! do u know how to make the sub navis posts no to appear on the main page? I cannot find the solution to it. ='(

add me @ nat7791@hotmail.com if anyone can help me. thanks alot.

14 January 2009 15:11 thepplway said...

may I know how do add a per view in my blogger?

i mean the per view under each article

Thanks

27 January 2009 21:52 Bobby said...

For those of you that received an error or the posts disappeared...change the word Label to Labels from the code...Good luck is working perfect on my blog

http://richmondsoccerblog.blogspot.com/

10 February 2009 08:29 Eric S. said...

I'm having the same problem as a few others. When I add the code, and save the template, all blog posts disappear.

The only thing I did was change from Sideblog to Side Note

Any help would be appreciated. http://collaborativewriters.blogspot.com/

11 February 2009 18:14 Zaim said...

Hi Amanda,

can you show to us how to make only one label showing on homepage (same as label page but on homepage). i need to make a news for my community blog. thanks for your time reading my demand.

1 April 2009 01:46 Daniel said...

I am using the Feedburner widget with the code that you provided and I changed the Sideblog label to what I needed. Then when I bring up my blog, the post are missing while the Feedburner still displays my feed in the sidebar. When I click on the title links in the Feedburner widget, it brings up the page for the post, but the post itself is missing. I can even scroll down and see the comments box, yet the post is missing.

Since my post does not show up when the link is clicked, I have to revert back to before pasting the code into the template. By reverting back, I see my post and the Feedburner feed. Then when I click on the links in the Feedburner widget it takes me to the post and the post is visible.

Is there any way to use your code and have the post be visible when the link in the Feedburner widget is clicked?

16 April 2009 20:10 Jacob Duchaine said...

Have you noticed there are several spam comments here? I think you should try to wash those off...

22 April 2009 02:19 GiDu said...

I am having the same problem as a few a of the others, too. I pasted the code and then all of my posts have disappeared. Please help!

23 April 2009 22:05
Anonymous said...

how can I manage my post just by click (1)(2)(3)(4) and so on.. everyone do that by I dont know how to do that...

29 April 2009 18:04 GiDu said...

I still can't get this code to work on my blog. I am having the same issue as Hackberry. My blog posts have disappeared. Then by reading further in the comments, Bobby suggested to change the word "label" to "labels." So I tried that, and it's still not showing my posts. Please help!

24 May 2009 01:40 sevan said...

very nice post

4 June 2009 05:51 Mr Binh said...

I have the label name"Top MTV". So I change it into "Top%20MTV", and It didn't work. Plz help me

4 June 2009 05:56 Nguyễn Thanh Bình said...

My posts have more than once label name.It could be the reason? Help me soon. Thanks

6 June 2009 05:19 VietNamBlogspot said...

I found another post on the internet. And now I can do it. If somebody can't do that. Can contact with me. my YM:xflowermoonx

17 June 2009 15:01 Andrea said...

I tried this and had the problem with my posts disappearing. I changed

!= data:blog.homepageUrl'>
to
== data:blog.homepageUrl'>

and

!= "Sideblog"'>
to
== "Sideblog"'>

It worked after I made those changes. In case it doesn't show up in this comment box, there are two exclamation points in the code that I changed to equal signs.

17 June 2009 15:05 Andrea said...

Scratch that last comment. Changing the exclamation sign to the equal sign made my blog show the posts with my label on the home page (which is actually what I wanted to do). Sorry about that!

21 June 2009 06:35 The Doc said...

This is not showing for my blog... can someone help?

All i get is an empty homepage!

13 July 2009 01:42 webmaster marine said...

cool tip; thank you, i think that i'll used this one!

3 September 2009 18:56
Anonymous said...

I got this to work. This code is completed with errors. It may have worked but it doesn't peformed well. hopefully i'm able to fix it completely or someone else can.

Post a Comment

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me