21 September 2010

How to add label-specific feeds to Blogger

A couple of months ago I wrote explaining how to add a auto-generated page based on a label to the Blogger standard widget. It proved fairly popular: it’s the most commented post my blog until now, tied with an older one about Google Reader’s “Send To” feature. I complained back then that I didn’t found a way to add the label-specific feed to the page, making it even more like a stand-alone mini-blog. In the mean time I gained more experience with Blogger’s template system and so discovered a way to add these extra feeds.

As most of the advanced tweaks, this will require manually editing the blog template, so it’s probably a good idea to back the original up first. Afterwards head on to the ‘Design’ section in the Blogger dashboard, switch to the ‘Edit HTML’ tab and check ‘Expand widget templates’. Here search for the following line, which is responsible for generating the standard feeds (RSS, atom and comments) on the blog:

<b:include data='feedLinks' name='feedLinksBody'/>

Right after this line and before the next </div> closing tag add this code and save the template:

<b:if cond='data:blog.searchLabel'>
<link expr:href='data:blog.homepageUrl + &quot;feeds/posts/default/-/&quot; + data:blog.searchLabel' expr:title='data:blog.title + &quot; - &quot; + data:blog.searchLabel' rel='alternate' type='application/atom+xml'/>

It basically checks if the current page is a “label search page” and, if that returns true, adds a new link pointing to the label-specific feed. Since the code uses data tags to detect the blog title, address and labels it can be used virtually on any Blogger blog without changes.

Blogger add RSS to label pages The new feed will function just like the built-in options; for example it will be detected by browsers and displayed in their standard feed interface along with the full site feed, as you can see in this screenshot taken in Firefox 4.

With some small changes it should also be possible to replace the default feeds with the label-specific feed, although I don’t think it’s such a good idea to take that choice away from readers. You will probably end up with a fragmented and hard to track audience: if you are using FeedBurner for statistics, it will not track subscribers and hits on these label feeds.


JB said...

Hello, I watched a YouTube video on how to redirect your blog to another URL using a javascript redirect code. The person shooting the video said this is a short-term solution because Blogger will most likely shut down the blog if you do this and they find out. I took this javascript code and put it on a Blogger Page to redirect to a specific Label (successfully)... So, my question is: Do you think Blogger will shut down my entire blog if I keep it this way and is your way the safer way to go??? Thanks! Jenn

JB said...

sorry, forgot to check off that i want email notification for response

George B. Moga said...

Hi Jenn!

I haven't heard of such a method myself, but I am sure this method I use and wrote about is safer. It doesn't use any kind of redirects or JavaScript.
Even if Blogger doesn't shut down your blog (and I doubt they would), there is a slim chance they will change something in the template system and break this JavaScript redirect.

Thanks for stopping by!

Brenda Clews said...

I couldn't find the feed in Chrome, but switched over to Firefox, easily found it, and now I have a page of specific posts that has a unique feed. Incredible. Brilliant is all I can say. And thank you.

Stylist On The Run said...

What happens if I can't find that link?

George B. Moga said...

What link exactly? The link to the feeds?

Joe said...

Hey George, I really like your blogger theme. Is there any way I could get a copy of your template?

George B. Moga said...

Thanks, Joe!
I made back-ups of my theme going back about two years on SkyDrive, you can check them out there. Be sure to back-up your own blog template before uploading any of the files and to change the sharing buttons, they are hard-coded in the template with my social media accounts.

Joe said...

Thanks a ton! What do you think? (http://thatwhichdothnotsuck.blogspot.com/) It is an awesome template. I gave you credit in the attribution block at the bottom of the page. Let me know if that is ok. Now I just need to know how you tweaked you Archive list. I went into the HTML under widgets and this is what mine looks like:

#ArchiveList {
column-count: 2;
-moz-column-count: 2;
-webkit-column-count: 2;
column-gap: 1em;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;

George B. Moga said...

Yes, it's OK.
You should probably remove my CSS code for the Archive List (what you quoted above in the comment), because it's meant for the an archive widget in list format (to save some vertical space) and if you have it set to hierarchy it looks a bit weird. I plan to do a post about customization of the archive widget with some more ideas I have.

Unknown said...

Hello...how to transfer my blog to other url...plzzz help me....

sukil Etxenike said...

Thanks so much for the info! Where did you get the 'data:searchLabel' boolean? I cannot find it anywhere in Blogger's help.

George B. Moga said...

I don't really remember at this point, but there are several unofficial sources online, for example this one: "7 Blogger Page Types: Analysis, Code Snippets, Data Matrix" or "Blogger: Globally conditional data tags for all page types"

Sam Nordberg said...

This is amazing. It's ridiculous that Blogger doesn't include this by default. Thank you for sharing.

Post a Comment