In this short guide we will create a new page that lists the feeds available on a WordPress blog. It’s a simple process and can be a handy overview of what data your site offers.
Step One: Creating a Feeds Template
We will need a template which dynamically outputs our feeds. The easiest way to do this to fit in with the theme you have installed is to make a copy of the page.php template and name it something like feeds.php
Next we will need to give the new template a label. Look for the following snippet of code or something similar at the top and change the label to “Feeds Page”. If you do not see it go ahead and add this.
/* Template Name: Feeds Page */
Next we will want to remove the code from this template that generates the page. We will replace it with the code that displays links to the feeds. Remove everything from the start of the WordPress loop to the end:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; endif; ?>>
including the edit_post_link function call.
Now we will want to add in some code to display the feeds. I’ve created some code to get us started which can be demoed on my personal blog’s feed page.
The code is
<h2>Global Feeds</h2> <ul> <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Latest Posts (RSS)'); ?>"><?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> <li><a href="<?php bloginfo('atom_url'); ?>" title="<?php _e('Latest Posts (Atom)'); ?>"><?php _e('Atom'); ?></a></li> <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('Latest Comments (RSS)'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> </ul> <h2>Feeds by Category</h2> <ul> <?php wp_list_categories('orderby=name&show_count=1&feed=RSS&title_li='); ?> </ul>
The first few lines simply link to the standard feeds: a feed of the latest posts in RSS format, a feed of the posts in ATOM format and a feed of latest comments in RSS format.
The last few lines (wp_list_categories) output some links to the feeds of the categories you have been posting in. You can edit the above code to fit your needs. For example you can set show_count to 0 to remove the amount of posts after the RSS link, or change “RSS” to say “Feed” instead or you can remove the listing of category feeds all together.
The hard part is now over. We need to let WordPress know we want a specific page for this template. We do this by creating a new page and setting the page template to use our new feeds template.
Step Two: Creating a Page
Login to the admin control panel and navigate to “Pages” and “Add New”. Name the page “Feeds” or something similar. Leave the content blank and then look to the right for “Template” under the attributes box. Click the dropdown and select our new template.
Once you publish the page and click the view button a beautiful new feed template should be displayed.
That’s it! Enjoy! This method can be adapted for other dynamic pages you may want to create and is employed by things like a custom archives page or a new dynamic home page. Let me know if this tutorial was useful or if you are using it on your own blog!