How Are Feeds Generated in WordPress?
Posted on November 15, 2007
Filed Under WordPress Coding, WordPress Syndication |
In WordPress, the feeds of posts and comments in formats of RSS or Atom are generated automatically and provided via specific URLs for syndication. Almost all themes provide feed links in either sidebar or header/footer. wordPress uses a build-in function “bloginfo” to get the feed URL. The feed link addresses for blog posts in RSS, RSS 2.0, and Atom formats, as well as RSS comment feed can be obtained by the following lines of code, respectively:
<?php bloginfo(’rss_url’); ?>
<?php bloginfo(’rss2_url’); ?>
<?php bloginfo(’atom_url’); ?>
<?php bloginfo(’comments_rss2_url’); ?>
The above bloginfo function obtains the feedURLs like:
http://www.wordpressprofit.com/feed/rss/
http://www.wordpressprofit.com/feed/
http://www.wordpressprofit.com/feed/atom/
http://www.wordpressprofit.com/comments/feed/
Resolved by internal rewrite rules, these URLs mapp to corresponding PHP files which are executed to generate feeds. These files are installed in the root directory of WP installation. You can generate the feed by running the PHP files from browser like:
http://www.wordpressprofit.com/wp-rss.php
http://www.wordpressprofit.com/wp-rss2.php
http://www.wordpressprofit.com/wp-atom.php
http://www.wordpressprofit.com/wp-commentsrss2.php
The above files generate feeds for all posts by default. If you want just generate feed from one specific category, you can add a parameter to point to the category ID, something as “cat=5″:
http://www.wordpressprofit.com/wp-rss2.php?cat=5
Another PHP file, wp-feed.php, also generate feeds. By default, it generate feeds in RSS 2.0 format:
http://www.wordpressprofit.com/wp-feed.php
If a parameter “feed” is provided to specific feed format, the feed in required format is generate. For example, the following URL generates RSS 2.0 comment feed:
http://www.wordpressprofit.com/wp-feed.php?feed=comments-rss2
As you have seen, WordPress has internal rewrite logic to map the wp-feed.php to different URLs, therefore, for instance, the RSS 2 post feed and comment can also be obtained by:
http://www.wordpressprofit.com/feed
http://www.wordpressprofit.com/comments/feed
Comments
Leave a Reply