Theming your newsletter is easy. You do not need to know anything else than how to make a wordpress theme.

Two themes are bundled with Gecka Newsletter plugin. One called Default, it is a basic but still nice html email theme, and Simple with is a simple and elegant html email theme.

Getting start

For you to begin making your first theme, first make a “newsletter” sub-folder in your current wordpress theme. Then copy one of the bundled themes folder inside it (from wp-content/plugins/gecka-newsletter/Themes). Rename the copied folder to the id of your new theme.

Once done, you need to add a line of code in your functions.php file:

Gecka_Newsletter::add_theme('theme_id', 'Nice theme name');

The ‘theme_id’ has to match your theme folder’s name. The ‘Nice name’ can be anything you’d like.

There you go, if you now go and create a new newsletter, the Theme meta bow should show your new theme in it drop down.

You can now go on editing your theme has you wish and using standard wordpress loops and functions.

Images

You can include images in your newsletters themes. Any theme can have an images sub folder. Any image that you link to that folder will be embedded in the resulting emails. Any other image will be kept as an external link.

The loop

When Gecka Newsletter starts parsing a theme’s index.php, the global $wp_query variable points to the newsletter post. So a really basic theme could look like:

<?php if ( have_posts() ): the_post(); ?>
<strong><?php the_title(); ?></strong>

<?php the_content(); ?>
<?php endif; ?>

That is easy. Now lets go down to adding custom loops. Imagine you want to show, next to the content a list of the latest 5 posts from the ‘newsletter’ categorie. It would look like this:

<?php $this->show_posts( 'categorie=newsletter&posts_per_page=5' ) ?>

The parameters are exactly the one used in WP_Query and the documentation can be found here. This command with basically show the post you want using the loop.php template of the newsletter theme used.

You can alternativly use an other template for the loop giving a second parameter being a string of the template name. For exemple to use the “recent.php” loop template you would:

<?php $this->show_posts( 'categorie=newsletter&posts_per_page=5', 'recent' ) ?>

The show_post function can also be used to display the posts you have selected manually in the backend when created a new newsletter. For that to happen, just make sure to ommit the first parameter (or give it the null value):

<?php $this->show_posts(); ?>

There is another nifty way to make use of your own loops. See the exemple bellow:

<?php
$this->new_loop(new WP_Query('categorie=newsletter&posts_per_page=5'));
while ( have_posts() ) : the_post(); ?>

<h2><?php the_title() ?></h2>
<?php the_content() ?>

<?php endwhile;
$this->end_loop();
?>

Advices

Making an HTML email template is a tricky task. Mail clients do not truly support css. When you’re building an email newsletter theme you should go back to old years and use tables for layout, in line css and inline HTML style attributes.

Then, do not forget to test your themes with multiple email clients. We personally test against Thunderbird, Outlook and Outlook express, and some webmails like Gmail or Roundcube.

Comments are closed.