How Do I Write My WordPress Feed for Tags & Searches?
I knew you get an RSS feed for posts with a specific tag in WordPress 2.3. But did you know you can get an RSS feed for a search too? Neither the tag nor the search rss feed seem to be really support by template tags so you can’t really access them normally within a theme or from a WordPress enabled webpage.
BTW If you have a site using FeedBurner to wrap RSS feeds and you are using FeedBurner FeedSmith plugin, then this won’t work. This plugin will wrap your posts RSS feed and ignore tag and search distinctions. I did a bit of hacking in th version of this plugin I use on this site to make this post work.
To get an RSS feed for posts with a specific tag, go to the tag archive and, if the site is using fancy permalinks, add “/feed/” to the end of the url. If it’s not using fancy permalinks, add “&feed=rss2″ instead. You can tell a site is not using fancy permalinks if the tag archive URL is like this: http://[site-url]/?tag=tag_slug (i.e. it contains a “?”).
For example: the URL for any posts tagged with WordPress on this site is:
http://holyworldwide.com/dustinhedrick/tag/wordpress/
The non-fancy-permalink version would be:
http://holyworldwide.com/dustinhedrick/?tag=wordpress
Now to get an RSS feed for that tag you change the URL like this for fancy permalinks:
http://holyworldwide.com/dustinhedrick/tag/wordpress/feed
Change the non-fancy permalink like this:
http://holyworldwide.com/dustinhedrick/?tag=wordpress&feed=rss2
For search, it’s slightly simpler as there does not seem to be a fancy permalink for searches. So do a search for wordpress on my site (you can use the searchbox up there in the top). You’ll end up with a URL like this:
http://holyworldwide.com/dustinhedrick/?s=wordpress
Now just add “&feed=rss2″ to the end and you get a feed for any posts on my blog that mention wordpress.
http://holyworldwide.com/dustinhedrick/?s=wordpress&feed=rss2
This feed will pick up any post I happen to mention the word “Wordpress” in.
Quite neat isn’t it? Now if there was some proper template tags for these feeds I’m sure more themes would natively support them.
What’s the use of using a search rss feed over a tag rss feed? Well you want your blog posts the way you want to read them don’t you? For example, I do not always tag any post about “wordpress,” I only tag those that are relevant to that. So, there you go!
How Do I Write My WordPress Feed?
I am adding this article here so that I can have it for reference later. Writing and working on WordPress feeeds has been tough, so this is here for my reference so that I am able to make changes necessary and quickly find what I need later. I hope that it helps you as well.
This article covers each of the many ways to access your WordPress-generated feeds. Several different URL formats are available for the various types of WordPress feeds — posts, comments, and categories — for both permalink and default URL structures. For each example, replace “http://domain.tld/
” with the URL of your blog. Note: even though your blog’s main feed is accessible through many different URLs, there are clear benefits to using a single, consistent feed URL throughout your site.
WordPress Post-Feed Formats for Permalinks
If you have permalinks enabled on your site, your main-content (posts) feed is accessible via the following URLs, depending on which feed format you would like to use:
http://domain.tld/feed/
(RSS 2.0 format)http://domain.tld/feed/rss2/
(RSS 2.0 format)http://domain.tld/feed/rss/
(RSS 0.92 format)http://domain.tld/feed/rdf/
(RDF/RSS 1.0 format)http://domain.tld/feed/atom/
(Atom format)
WordPress Post-Feed Formats for Default URLs (non-permalink)
By default, your main-content (posts) feed is accessible via the following URLs, depending on desired format:
http://domain.tld/wp-rss2.php
(RSS 2.0 format)http://domain.tld/wp-rss.php
(RSS 0.92 format)http://domain.tld/wp-rdf.php
(RDF/RSS 1.0 format)http://domain.tld/wp-atom.php
(Atom format)
WordPress Post-Feed Formats via Query String (non-permalink)
Alternately, your main-content (posts) feed is also available at the following URLs, depending on desired format:
http://domain.tld/?feed=rss2
(RSS 2.0 format)http://domain.tld/?feed=rss
(RSS 0.92 format)http://domain.tld/?feed=rdf
(RDF/RSS 1.0 format)http://domain.tld/?feed=atom
(Atom format)
Display your Default Post-Feed URLs
To determine/display the default posts feed URL for your blog’s main content, place any or all of these template tags into a useful location in one of your theme files:
<?php bloginfo('rss2_url'); ?>
(RSS 2.0 format)<?php bloginfo('rss_url'); ?>
(RSS 0.92 format)<?php bloginfo('rdf_url'); ?>
(RDF/RSS 1.0 format)<?php bloginfo('atom_url'); ?>
(Atom format)
WordPress Main Comments Feed
Your blog’s main comments feed is available only in RSS 2.0 format, but there are several URL options from which to choose:
http://domain.tld/comments/feed/
(Permalink format)http://domain.tld/wp-commentsrss2.php
(Default format)http://domain.tld/?feed=commentsrss2
(Query-string format)
Display your Main-Comments Feed URL
To display the default URL for your main comments feed, add this template tag to your theme file and load the page in your browser:
<?php bloginfo('comments_rss2_url'); ?>
Post-Specific Comment Feeds
By default, every post also delivers its own feed featuring all of its comments. To display feed URLs for individual, post-specific comment feeds, place this template tag anywhere in the main post loop or comment loop 1:
<?php comments_rss_link('Subscribe to comments on this post via RSS-2.0 feed'); ?>
Alternately, to display the comment feed URL for any specific post, simply append either of the following to the original post URL:
feed/
(Permalink format)?feed=rss2
(Default format)
Here is an example of each method for a generalized post URL:
http://domain.tld/individual-post/feed/
(Permalink format)http://domain.tld/individual-post/?feed=rss2
(Default format)
Update: When using default (non-permalink) URLs, the post-specific comment feeds are available via the following format:
http://domain.tld/?feed=rss2&p=123
..where “p=
” references the post ID .
Category Feeds
To display individual category feed URLs, use either of the following formats 2:
http://domain.tld/category/categoryname/feed/
(Permalink format)http://domain.tld/wp-rss2.php?cat=33
(Default format)