Advertisement
WordPress

Build a 'WordBurner' Email Newsletter Manager using WordPress and FeedBurner

by

There are lots of different ways to communicate with your users these days. RSS feeds, SMS, & sites like Twitter have changed how we speak to our audience. But for my money, you can't beat the personal touch of a good ol' email newsletter.

Of course keeping up a newsletter can take effort, but in this tutorial I'll show you how to use your regular Wordpress website combined with Feedburner to make a simple email newsletter manager.

There are many dedicated and great email newsletter solutions on the market. This is not intended to replace them, but rather to offer an easy way to email visitors of your personal site or blog a round up of updates and news without having to install new software or set up new systems.

What we are going to do is:

  1. Create a 'Newsletter' category in Wordpress
  2. Hide it from regular posts
  3. Create an RSS feed for that category
  4. Give that feed to FeedBurner and use their email update service to deliver our newsletter.

This tutorial is based on the default theme in Wordpress 2.5.1. If you are using a different theme, some code may be in a slightly different place and you may have a few extra files, but the principles are still the same.

Once you're all set up, sending out an email newletter will be as easy as writing a blog post, so let's get started!

Step 1 - The 'Newsletter' category

First of all we create a new category in Wordpress called 'Newsletter'. Sign in to your admin area and go to Manage > Categories - click Add New. For Category Name let's choose 'Newsletter' and Category Slug will be 'newsletter' and click 'Add Category'.

Adding a category in Wordpress

With our Newletter category created, we need to get its ID. Since Wordpress version 2.5, seeing a category's ID has become a little tricky, the best way to see it is to hover over the category in Manage > Categories and look at the status bar in your browser for the cat_ID part of the link as shown in the screenshot below:

Category ID link

In this example, our category ID id is 6. This number will probably be different for you, make a note of it.

For the rest of this tutorial you will see this number represented by {YOUR cat_ID}. Wherever you see {YOUR cat_ID}, replace this with your number.

Step 2 - Hiding the 'Newsletter' category

Now we should hide this category away from our main blog/site. Firstly we'll hide it from the category list that appears in the Wordpress sidebar. A category will only show in the sidebar when it has at least one post assigned to it, therefore the Newsletter category will not show until we write and publish a post for it. But we don't want that to happen, so...

Open up your theme's sidebar.php file (/wp-content/themes/your-theme-name/sidebar.php) and look for:

wp_list_categories('show_count=1&title_li=<h2>Categories</h2>');

Change this to:

wp_list_categories('show_count=1&exclude={YOUR cat_ID}&title_li=<h2>Categories</h2>');

This will exclude our Newsletter category from showing up in the category list in our sidebar. (Ref.)

Step 3 - Hide Posts

Next, we want to stop our newsletters from showing up in our regular posts. Excluding categories from 'The Loop' (where Wordpress displays our posts) seems to be a bit problematic. After trying this way and that way, there were still problems with paging breaking, it simply not working and sql errors. We want to keep this method as simple as possible without resorting to plugins so we'll use the following method: (Ref)

Open up the following files in your Wordpress theme:

  • index.php (/wp-content/themes/your-theme-name/index.php)
  • archive.php (/wp-content/themes/your-theme-name/archive.php)
  • search.php (/wp-content/themes/your-theme-name/search.php)

In each of the files, where you see the following code:

<div class="post">...

add this line just above it:

<?php if (in_category('{YOUR cat_ID}')) continue; ?>

so now our code in those 3 files will look like this:

<?php if (in_category('{YOUR cat_ID}')) continue; ?>
<div class="post">... etc.

We are telling Wordpress not to display any posts from our Newsletter category. Whilst this technique is the least problematic, there is something that's important to understand. Quoted from the Wordpress documentation:

"Please note that even though the post is not being displayed it is still being counted by WordPress as having been shown -- this means that if you have WordPress set to show at most seven posts and that two of the last seven are from Category 3 then you will only display five posts on your main page. If this is a problem for you, there is more complicated hack you can employ described in the Layout and Design FAQ or you can use query_posts if you only need to exclude one category from the loop." (Ref)

The above is also true of search results. However if you are sending out a newsletter about once a month, it shouldn't be a real problem.

We also don't want any posts in the 'Newsletter' category to show up in navigation when viewing single posts / permalinks. Open up single.php (/wp-content/themes/your-theme-name/single.php) and search.php (/wp-content/themes/your-theme-name/search.php) and change the following:

<div class="navigation">
<div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
</div>

to:

		<div class="navigation">
<div class="alignleft"><?php previous_post_link('%link', '%title', FALSE, '{YOUR cat_ID}') ?></div>
<div class="alignright"><?php next_post_link('%link', '%title', FALSE, '{YOUR cat_ID}') ?></div>
</div>

(Ref 1, 2)

Step 4 - Hiding 'Newsletter' in our RSS

Now that we have our category set up we can move on to the RSS feed that will power our newsletter.

Just as we didn't want the 'Newsletter' category to show in our sidebar or in our posts, we also don't want it showing up in our website's regular RSS feed.

The url for your Wordpress site's RSS feed should be something like http://yourwpsite.com/?feed=rss2. To exclude our 'Newsletter' category we 'add &cat=-{Your cat_ID}' to the end so it now reads http://yourwpsite.com/?feed=rss2&cat=-{Your cat_ID}.

In the file header.php (/wp-content/themes/your-theme-name/header.php), you should see a line that reads:

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />

change this to:

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="http://yourwpsite.com/?feed=rss2&cat=-{Your cat_ID}" />

If you already have your main Wordpress feed running through FeedBurner, you'll need to sign in to FeedBurner, go to 'My Feeds', choose your feed and go to 'Edit feed details...' and change the 'Original feed' option.

Step 5 - Creating our RSS feed!

Now we create an RSS feed for just the 'Newsletter' category by using the URL http://yourwpsite.com/?feed=rss2&cat={Your cat_ID} - this is now your newsletter's RSS feed url.

That was easy!

Step 6 - Burning the 'Newsletter' feed

Now we have an RSS feed for our newsletter, sign in to FeedBurner and enter your newsletter's RSS feed url into the 'Start FeedBurning now' form:

FeedBurner form

or 'Burn a feed right this instant':

FeedBurner form

Click 'Next »'.

Give your newsletter a name and new url:

Naming your feed in FeedBurner

Click on 'Activate Feed'. You can then add extra bits via 'Next Step' if you wish or 'Skip directly to feed management'.

Step 7 - Turning the Feed into an Email Newsletter

Almost done! Once FeedBurner tells you that your feed is ready, click on 'Publicize' up the top:

Publicize navigation

then choose 'Email Subscriptions' on the left:

Email Subscriptions

Leave the default settings and click 'Activate'.

You will now be given the 'Subscription Form Code' or 'Subscription Link Code' which allows your site visitors to sign up for the newsletter. Decide if you'd like a form or a link, copy the appropriate code and paste it into your site. The sidebar might be a good place to paste it for now. You could also add a 'Sign up for the newsletter' title above the code just to make it clear.

The number of newsletter subscribers' and their email addresses can be viewed in your FeedBurner account, under Publicize > Email Subscription. You cannot sign people up on their behalf, which is a good thing. Users must click on a verification link sent to their email address before they are signed up.

Step 8 - Sending out a newsletter

Now all the fiddly stuff is done, sending out a newsletter is as simple as publishing a post to the 'Newsletter' category.

What happens is that when you post to the 'Newsletter' category, the RSS feed we created for that category updates. This alerts the FeedBurner email service which grabs your update and emails it out to your list subscribers.

When you publish a 'newsletter' post, the email is not sent out straight away, but at the end of that day. This can allow you to edit or make adjustments to your mail-out before it is sent.

Here is how the newsletter looks in Gmail:

Newsletter example

Note that in this test scenario my newsletter is called 'WP Dev', that's just the title of the Wordpress blog I set up to test this, the newsletter will pick up the title of your Wordpress site. It says 'Newsletter' as that is what I called my newsletter category.

I hope this tutorial eases any newsletter pains you may be having. Enjoy!

Final Notes

  • You can test this all out by signing up and posting a newsletter to yourself before putting the sign up form on your site.
  • Be sure that your RSS feed is set to show 'Full Text' under Settings > Reading in the Wordpress admin area:
    RSS feed options in Wordpress

    Otherwise people will just receive a snippet of your newsletter instead of the full thing.

  • You can follow this method for multiple categories, often by seperating category IDs with commas. I haven't gone into this during this tutorial but you can find out more by clicking the 'Ref' links you see in this article.
  • By their nature, RSS feeds are very adaptable. If you come up with an interesting take or build on this technique please leave a comment about it.
  • If you wanted to go a newsletter crazy, you could go as far as setting up a Wordpress blog just for newsletters, but that's another story.
  • As mentioned at the start, this was tested on Wordpress 2.5.1 using the default theme. Your code may differ somewhat depending on the theme you are using but the principles remain the same.
  • It seemed that the trickiest part in creating this tutorial was getting Wordpress so successfully ignore a category without it having a knock-on effect or breaking other parts of the site. There is a plug-in called Ultimate Category Excluder that might be worth a look but I have not tried or tested it.
Related Posts
  • Code
    WordPress
    A Guide to Using FeedPress with WordPressA guide to using feedpress with wordpress
    FeedBurner still works great, but it hasn't been updated much in the last few years, and people are worried that Google, owner of FeedBurner, may close it down especially with the track record they've had over the past few years. So for those of us who want to continue tracking statistics about our subscribers, what options do we have available?Read More…
  • Code
    Theme Development
    Custom Controls in the Theme CustomizerTheme customizer custom control 400
    In the last article, we explored the advanced controls available in the Theme Customizer, and how to implement them. We’re going to look at how to create our own custom control, allowing you to choose which Category of Posts are displayed on the home page. To get started, download version 0.6.0 of our Theme Customizer Example.Read More…
  • Code
    Theme Development
    Creating a WordPress Theme from Static HTML: Creating an Archive TemplateCreating wordpress theme from html 400
    If you've been working your way through this series, you now have a functioning theme with two page templates. The steps I've demonstrated to this point are: preparing your markup for WordPress converting your HTML to PHP and splitting your file into template files editing the stylesheet and uploading your theme to WordPress adding a loop to your index file adding meta tags, the wp_head hook and the site title and description to your header file adding a navigation menu adding widget areas to the header and sidebar adding widget areas, a colophon and the wp_footer hook to the footer file creating template files for static pages. Read More…
  • Code
    Theme Development
    Creating a WordPress Theme from Static HTML - Creating a Page TemplateCreating wordpress theme from html 400
    So far in this series, I've shown you how to create a fully functioning WordPress theme from static HTML. We've covered the following steps: preparing your markup for WordPress converting your HTML to PHP and splitting your file into template files editing the stylesheet and uploading your theme to WordPress adding a loop to your index file adding meta tags, the wp_head hook and the site title and description to your header file adding a navigation menu adding widget areas to the header and sidebar adding widget areas, a colophon and the wp_footer hook to the footer file. At the moment, your theme only has one template file for displaying content—the index.php file. A powerful feature of WordPress is the ability to use template files for different kinds of content.Read More…
  • Code
    Theme Development
    Creating a WordPress Theme From Static HTML: Creating Template FilesCreating wordpress theme from html 400
    In the first part of this series, I showed you how to prepare your HTML and CSS files for WordPress, ensuring the structure would work, the code was valid and that the correct classes were being used. In this tutorial you'll learn how to take your index.html file and split it up into a set of template files for use by WordPress.Read More…
  • Code
    Theme Development
    How to Integrate Bootstrap Navbar Into WordPress ThemeBootstrapd 400
    Have you ever wanted to speed-up the process of theme development? I assume the answer is "yes" and you already know about Bootstrap and use it in mock-ups for development. This raises the question: "How can you integrate Bootstrap components into a WordPress theme?"Read More…