WordPress rss feed

RSS feed of posts of the site: site.com/feed/ or site.com/?feed=rss2;

RSS feed of comments of the site: site.com/comments/feed/ or site.com/?feed=comments-rss2;

RSS feed of comments of the specific post or page: site.com/page/feed/ or site.com/?page_id=2&feed=comments-rss2;

RSS feed of custom post type: site.com/feed/?post_type=news or site.com/?feed=rss2&post_type=news;

RSS feed of custom post types: site.com/feed/?post_type[]=post&post_type[]=news or site.com/?feed=rss2&post_type[]=post&post_type[]=news;

WordPress posts rss feed url:

echo '<a href="'.get_bloginfo( 'rss2_url' ).'">'.'posts rss feed</a>';

WordPress comments rss feed url:

echo '<a href="'.get_bloginfo( 'comments_rss2_url' ).'">'.'comments rss feed</a>';

WordPress category rss feed url:

if ( is_category() ) {
	echo '<a href="'.get_category_feed_link( get_query_var( 'cat' ) ).'">'.single_cat_title( '', false ).' category rss feed</a>';
}

WordPress tag rss feed url:

if ( is_tag() ) {
	echo '<a href="'.get_tag_feed_link( get_query_var( 'tag_id' ) ).'">'.single_tag_title( '', false ).' tag rss feed</a>';
}

WordPress author rss feed url:

if ( is_author() ) {
	echo '<a href="'.get_author_feed_link( get_the_author_meta( 'ID' ) ).'">'.' author rss feed</a>';
}

Get rss feed

$rss = fetch_feed( "http://www.reddit.com/.rss" );

if ( is_wp_error($rss) ) {
	if ( is_admin() || current_user_can('manage_options') ) {
		echo '<p>';
		printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
		echo '</p>';
	}
	return;
}

if ( !$rss->get_item_quantity() ) {
	echo '<p>Apparently, there is nothing happening on Reddit!</p>';
	$rss->__destruct();
	unset($rss);
	return;
}

echo "<ul>\n";

if ( !isset($items) )
	$items = 10;

foreach ( $rss->get_items(0, $items) as $item ) {
	$publisher = '';
	$site_link = '';
	$link = '';
	$content = '';
	$date = '';
	$link = esc_url( strip_tags( $item->get_link() ) );

	$content = $item->get_content();
	$content = wp_html_excerpt($content, 250) . ' ...';

	echo "\t<li><a href='$link'>$link</a> - $content</li>\n";
}

echo "</ul>\n";
$rss->__destruct();
unset($rss);

2 thoughts on “WordPress rss feed”

Leave a Comment