WordPress as an Online Magazine

WordPress is more than a blog engine. It’s an easy-to-use CMS (Content Management System) perfect for running a “webzine.” I’m not a big fan of most CMS systems, though I’m a huge fan of WordPress. Joomla is too convoluted and Drupal isn’t that great either. I’m not going to go around the web bashing other CMSes right and left, but I do like to point out WordPress as a viable option for “non-blog” sites.

The Main Page

The main difference between a blog an a webzine is the index page. While the typical blog just shows the most recent posts, a webzine goes beyond that. There are a lot of ways to display content on the main page. Here are some examples of webzines:

Look around the internet. You’ll find no shortage of different “non-blog” index styles. Do you see how they are all similar? They highlight different types of content. “Featured” posts, “normal” posts, “news,” etc. Before you get into developing your webzine too much, map out the main page on paper. Decide what types of content you will have, and how you will display them on the main page.

How do you put more than one block of posts on a page? It’s not that hard…if you’re used to editing templates (which I assume you are, if you’re making your own theme). When you create the index.php template, you put in more than one Loop.

Suppose you wanted to put a box on the index with a list of links to featured posts. I do this on the Webmaster-Source homepage (in the middle column) if you want to take a look. You would create a category called “Featured Posts” (noting the category’s id) and use this code somewhere on the homepage:

<ul>
<?php
$postslist = get_posts('category=2&order=DESC&numberposts=5');
foreach ($postslist as $post) :
setup_postdata($post);
?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
endforeach;
?>
</ul>

For this to work, you need to replace 2 with the category id for your Featured Posts category.

By creating categories like “Features,” and “News,” and using multiple Loops to pull their most recent entries to the main page, you can divide-up your articles like a magazine. No matter how you want the index to look, you can do it with WordPress and some ingenuity.

Template Mania

Now that you have all these different types of content, you’ll need more ways to display them. What if you don’t want the category archives for the “News” category to look the same as the normal archives? What if you want it to look more customized…sort of like the index page? Here’s a little secret: You can have more than one category.php template. That’s right. If you copy the category.php template and rename it category-3.php WordPress will use category-3.php instead of category.php when the category archive for the category with the id of 3 is being displayed. That leaves you with plenty of room for customization.

Want to take that even further? How about having different single.php templates for posts in different categories? Just rename your normal single.php template to normal-single.php and create as many alternate single templates as you need. Next, create a new single.php and do something like this:

<?php
$post = $wp_query->post;
if (in_category('3')) {
include(TEMPLATEPATH . '/featuredpost-single.php');
} else {
include(TEMPLATEPATH . '/normal-single.php');
?>

Using if statements, you can tell WordPress to use different templates depending on the category. If you only need to make a minor tweak for a certain category, you don’t need to go so far as to have a separate template. You can just put

<?php if (!in_category('3')) { ?>
Whatever you want to appear on permalink pages that are not in category 3.
<?php } ?>

I use in_category() on my single post template. That way I can cut-out some of the extras if a post is in my Sideblog category.

Custom Fields

Custom Fields are an interesting, and underused, part of WordPress. They’re a way to add metadata to your posts. There are scores of things you can use them for in a webzine environment. Take a peak at NorthXEast.com. See the images next to the posts? They’re not exactly in the actual posts. They’re (I assume) done using Custom Fields.

To match an image up with a post, you use a “key” of “postimage” (or something like that) and for the value you put the URL of the image. Then you can put the image near the post like this:

<img src="<?php get_post_meta($post->ID, 'postimage', true); ?>" />

Simple.

You can do much more with Custom Fields than display images, but this is a common use.

Further Reading

  • http://elcadillo.org Guerry

    HI!

    (Templatemania) (I want different single.php templates for posts in different categories)

    The new single.php is just with these short code?

    Thanks!

  • http://www.webmaster-source.com Matt

    Basically, yes. You create more than one single.php template (with different names), and include them in the template called “single.php” with the code shown above. Make sure you make the appropriate changes to the include() commands.

    Oh, and be sure to back-up your blog!

  • http://elcadillo.org Guerry

    Thanks, Matt!

    I run WP 2.2.1
    I follow each step, but I get this error:

    Parse error: syntax error, unexpected $end in /home/…./wp/wp-content/themes/default/single.php on line 7

    I Try with:

    if (is_category(9)) {
    include(TEMPLATEPATH . ‘/template-venezuela.php’);
    } else {
    include(TEMPLATEPATH . ‘/normal-single.php’);
    }

    But not work, only normal-single.php is displayed.

    I try with other plugs like Custom Post Templates (Ryan Boren), Post Templates by Category (Kaf Oseo), and nothing work. I don’t understand .
    Thakns!

  • http://www.webmaster-source.com Matt

    Try using this code instead:

    if (in_category(‘9′)) {
    include(TEMPLATEPATH . ‘/template-venezuela.php’);
    } else {
    include(TEMPLATEPATH . ‘/normal-single.php’);
    }

    Basically I changed “is_category(9)” to “in_category(‘9′)”. Let me know if it works.

  • http://elcadillo.org Guerry

    I was mistaken. On my index.php (customized, default theme)
    it lacked this part of code in head —> ?php wp_head(); ? /head

    I’m using the first code

    $post = $wp_query->post;
    if ( in_category(‘9′) ) {
    include(TEMPLATEPATH . ‘/template-venezuela.php’);
    } else {
    include(TEMPLATEPATH . ‘normal-single.php’);
    }

    Now, it works!

    Your help has been my “salvation”
    Thank you so much, Dear Matt!

  • James

    Hi Matt,

    Thanks for the info. Here is my question. What if I want a custom category.php page that combines 2 discreet categories (say 3 and 9). i.e. the stuff that would be shown in an archive page if I typed in the URL /?cat=3,9. What would that custom category page by named category-(?).php. Is it possible to create a custom category page to do this. Your help is appreciated. Thanks.

    James

  • http://www.webmaster-source.com Matt

    I looked around the WordPress Codex, and I ran some Google searches. I don’t think it is really possible.

    However, I found something that may work for you. What if you created a template file, and used query_posts to display the two categories. You could just create a Page, and set it to use the template you created. I’m not sure if that would meet you needs, but it’s the best I could think of right now (you may also want to try the official WordPress forum).

  • James

    Hi Matt,

    I thought you might know off the top of your head. I didn’t expect you to do all that work. Thanks for the effort. I think you are correct. In fact, I initially found your post when I was doing the same thing you did in trying to solve the problem. I did post the question on the wordpress.org forum but never got a response. I thought there might be an easy way to do it without creating a page. I guess not. I’ll just go forward with that solution. Thanks again for the help.

    James

  • http://www.pwllheli.org Aran

    Hi there Matt,This looks like exactly what I’ve been looking for (with increasing desperation!) – very many thanks for that.

    However, I’m getting the same parse error as is listed above:

    Parse error: syntax error, unexpected $end in /home/…./wp/wp-content/themes/mimbo2.2/single.php on line 7

    I’ve checked carefully that I have ‘in’ instead of ‘is’…!

    What I’ve got is:

    $post = $wp_query->post;if (in_category(‘8′)) {include(TEMPLATEPATH . ‘/single-saesneg.php’);} else {include(TEMPLATEPATH . ‘/single-cymraeg.php’);

    within the php brackets.

    Is there anything obviously wrong to your more practiced eye?� I would be very grateful indeed for any pointers on this…:-)

    Many thanks for your work and for any advice you can give,

    Aran

  • http://www.webmaster-source.com Matt

    Well, first try putting a “}” at the end, like this: else { include(TEMPLATEPATH . ‘/single-cymraeg.php’); }   It may be the problem.