Creating an RSS Feed with an offset in WordPress

Mailchimp is a powerful platform for sending out html based email newsletters, and even includes the ability to create automated emails from your blog through the RSS feed, there is only one major flaw in the Mailchimp RSS based mailing system. Mailchimp lacks the ability to offset your RSS feed. Offsetting would allow for the ability for your most recent blog post to be featured and include an image, while also providing a list of other recent posts, but in a different format, such as with no image or no excerpt.

Offsetting can be a powerful tool for creating RSS driven html emails!

With a recent update to my subscription based notifications template, I wanted the ability to use post offsetting in my layout. Since Mailchimp lacked this functionality the solution was clearly to just make a new RSS feed that didn’t include the most recent post. While I expected this would present a challenge it turned out to be much easier than I expected.

To save others the trouble of figuring this process out, I have provided the required code to make it work below.

If your interested in providing automated html email based notifications with your blog but lack the coding skills to make it happen; TCH is more than happy to help you out with this problem, for a small fee of course. Just drop us a line and let us know how we can help by emailing [email protected].

Creating an RSS Feed with an Offset of 1

Add the below code to your child theme’s Function.php file. Replace the words offset1 with what ever you want to name your feed file.

add_action( 'after_setup_theme', 'my_rss_template' );
/**
 * Register custom RSS template.
 */
function my_rss_template() {
	add_feed( 'offset1', 'my_custom_rss_render' );
}
/**
 * Custom RSS template callback.
 */
function my_custom_rss_render() {
	get_template_part( 'feed', 'offset1' );
}

Create a new feed template file and place it in your child theme’s directory. You need to name the file feed-offset1.php, where offset1 is what ever you want the file to be called. If you want your offset to be something other than 1, simply change the $more=1 to be any number you desire.

<?php
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
echo '';
do_action( 'rss_tag_pre', 'rss2' );
?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"	>
	<atom:link href="" rel="self" type="application/rss+xml" />
	

2 comment(s)

Wondering. If I wanted multiple configurations, maybe an offset 1 and an offset 2, would I do this?

add_action( ‘after_setup_theme’, ‘my_rss_template’ );
/**
* Register custom RSS templates.
*/
function my_rss_template() {
add_feed( ‘offset1’, ‘my_custom_rss_render’ );
add_feed( ‘offset2’, ‘my_custom_rss_render’ );
}
/**
* Custom RSS templates callback.
*/
function my_custom_rss_render() {
get_template_part( ‘feed’, ‘offset1’ );
get_template_part( ‘feed’, ‘offset2’ );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses "tracking cookies" on your computer to deliver the best experience possible. To learn how these cookies are used please review our Privacy Policies by clicking here. Your continued use of this site indicates you have read and agree to our Terms of Use and Privacy Policies, collectively known as "the agreement". If you do not agree to this agreement or are not authorized to utilize the site because of the conditions of the agreement. Please close your browser now. This notice will be provided once every seven calendar days.
Close