Last semester, when we launched our new DTLT Web site, I was hoping to really use it as a tool for getting the word out to our faculty about news, upcoming events, professional dev. opportunities, and showcase projects. Ideally, I wanted to use it as a hub from which all of this information could be delivered.
What I really wanted was an easy way to create a newsletter that included content from the new site. I planned on sending these out to all UMW faculty about once a month. By using the site to generate the newsletter, I wouldn’t have to build it from scratch. After all, everything that I wanted to share with the faculty should, ideally, also have some presence on the Web site. What I quickly discovered, however, was that there was no easy way to use the content I was generating on the site to create such a newsletter.
WP has a few newsletter/subscription plugins, but they seem to do one of two things: send updates to subscribers whenever a new post is generated or simply generate a list of emails that you can then use with some other newsletter program. Neither of these was really ideal. I was pretty certain that most faculty wouldn’t appreciate an email from DTLT every time we added something to the site. And I’m not using any other third-party program to generate a newsletter. I also didn’t want an opt-in solution. I really wanted to be able to send something to all faculty using our internal all faculty email list at the University.
What I wanted was very simple: a basic text of html email that I could send to faculty with a list anof new items and links to read more.
After a few months of tinkering (and getting distracted by other projects), I’ve finally come up with a solution.
Basically, I created a custom page template called template.php newsletter.php which can be applied to page when you create it. The text you put in the page becomes the text at the top of the newsletter. (“Welcome Back! We hope you had a nice break. Here is our latest newsletter. . .”). Then you use a custom field (“issuecat”)on the page to define a category number. In my case, I created a category called “January 2010 Newsletter” and entered the corresponding category number into the custom field.
When I view the page, I get a specially formatted page, showing the text of the page and the content (up to the “More” divider”) for whatever posts I put in my category. At the top of the page is a link to the actual page on the blog in case someone can’t view the HTML email. I’ve also allowed for custom images to be displayed with the posts through the use of another custom field: newsimg. (Although I’m not using these at the moment.)
Getting the newsletter into an email program takes a little bit of trickery, and it depends a lot on what email program you’re using. In my case, I work on a Mac and use Mail or Entourage to send through our Microsoft Outlook mail server. Sending an HTML email that you’ve created elsewhere can’t be done out of the box in either of these programs. However, for Entourage there is a script that will allow you to send a complex HTML email. Basically, you save the WP newsletter page to your computer and then use this script to point Entourage to the file. The message should preserve all it’s formatting. In Mail, you can copy and paste the text of the newsletter into an email message. This won’t preserve images, but it will preserve the basic formatting.
In all honestly, I would love to do this with just a plan text email. There’s no particular reason why it has to be HTML and I’m not huge fan of HTML email. However, in order to have something that gets automatically generated (so that I’m not spending a bunch of time doing even basic line/paragraph breaks) by WP, this seemed like the only solution.
The code to make the template itself work is nothing fancy — just a variable for the category custom field that’s used to execute a second query on the page to grab the appropriate posts. The ordering is just descending chronological. I’d like to play around with grouping the posts based on type (event, news, project, etc.) but that’ll have to be for the next iteration.
The formatting of the page is based on a basic HTML email template I found online (can’t find the link right now, but I’ll try to add it later). As it turns out, the HTML you use to generate email is like generating a circa-1997 Web page. Figuring out how to make that work was painful.
If anyone cares to try it out, here’s a link to the template file, zipped up. You’ll have to make some changes to the code (for the page title, image, etc.) Also, full disclosure: I’m not a programmer, just a hack. There may be a better way to do this, code-wise. I just know it served my purposes. 🙂