How to create a wordpress magazine theme using Twenty Ten – Part 4

Reading Time:

[Tweet](https://twitter.com/share)
**This is part three of a short series outlining how to tweak a wordpress template to get some magazine style functionality. [Part one](http://www.andydickinson.net/2010/09/21/how-to-create-a-wordpress-magazine-theme-using-twentyten/), [Part Two](http://www.andydickinson.net/2010/09/22/how-to-create-a-wordpress-magazine-theme-using-twenty-ten-%E2%80%93-part-2/) and P[art three](http://www.andydickinson.net/2010/09/23/how-to-create-a-wordpress-magazine-theme-using-twenty-ten-%E2%80%93-part-3/) are available here.**

In part three of this short series we looked at adding a second loop to our edited index page to get round the problem of our Featured Post being repeated on the front page. In this final part I’ll look at adding a thumbnail and styling up the page.

Image thumbnails

Over the years, theme designers magazine themes have come up with many weird and wonderful ways of getting thumbnail images on front pages. But it’s only recently that WordPress developers added solid support.

One of the things I wanted to do with this series is to avoid too much tweaking of files. So I’m going to be relying on some of the core features for wordpress to get thumbnails on the page rather than fancy tricks. So beefore we get back in to editing the template code to display thumbnails there are few things we need to check.

Media settings

When you add an image to a blog post you are given the option to add it as a thumbnail, medium, large or original size. We are going to be using the standard function to to get a thumbnail (you may remember it from part 1) and it uses the same shorthand to get an image

[php]

[/php]

The sizes for each these are set in the Media section of the settings tab.

![](https://i1.wp.com/www.andydickinson.net/wp-content/uploads/2010/09/Media--500x193.jpg?resize=500%2C193 "Media")
The image size options
So our edited front-page is going to be based on these sizes. If you want any other sizes for your page you should set them here first. The downside of working this way is that this will impact on the sizes of images placed in your blog posts -that’s the trade off of keeping things simple.

Adding a featured image.

Version 2.9 of WordPress included a new post thumbnail option which allowed you to define an image to display “*as the representative image for a Post or Page. The display of this images is up to the theme. This is especially useful for “magazine-style” themes where each post has an image.” *The feature was renamed “featured image” in wordpress 3.0 – I’m guessing to avoid confusion with thumbnails. Whatever it’s called it’s ideal for our front page.

![](https://i2.wp.com/www.andydickinson.net/wp-content/uploads/2010/09/featured1-500x159.jpg?resize=500%2C159 "featured1")
Adding a featured image
When you write a post you should see a panel called Featured Image. Clicking the *Add featured image* link opens up a standard image browser. You simply find the image you want to use and click the *Use as Featured Image* link and you’re done.

So before we go on, add a featured image to the post in your Featured Story category.

Adding the thumbnail to the template

Now that we have set up the Featured image we can edit our template file and get an image on our frontpage.

Open up the Main Index Template file and add the following and edit the first loop so it looks like this:

[php]

[
Our medium thumbnail
Now do the same with the second loop.

[php]

[
Thumbnails added to each loop
And that’s it.

Adding some style.

Technically we are done. All the elements we want are on the page. But it’s not looking as good as it could be. We need to add some styling information and make some amendments to the stylesheet file.

I’m not going to go in to a big write up of CSS here (try the excellent W3Schools for a basic intro) but if you’re interested in tweaking wordpress templates it’s one of those areas you’ll be spending a lot of time with.

For now, its enough that when dealing with stylesheets, we need to keep our eye open for two things; divs and classes.

Divs

If you look at the Main Index template file, you’ll see the following lines
[html]

……
[/html]

The div tag is an html element that doesn’t actually display anything by default, it defines a section of the page. When it comes to look and feel, the key part is the id . This ‘connects’ the div to display instructions defined in the stylesheet. The style definition for container is:

[css]

container {

float: left;
margin: 0 -240px 0 0;
width: 100%;
}
[/css]

Anything that sits between the div tags will be effected by this definition.

Classes

One restriction of ID’s is that you can only use them once on a page. So if you have a lot of elements on a page that you want to style you have to use a class. Remember the html we used for our post title:

[php]

[ [/html]That means we take the standard H2 formatting and add some custom styling.

[css]

content .entry-title {

color: #000;
font-size: 21px;
font-weight: bold;
line-height: 1.3em;
margin-bottom: 0;
}
[/css]

This says, any time the class entry-title (denoted by the full-stop) is referenced inside the content div (denoted by the # symbol) apply the following styling.

Image Alignment

The first thing to sort out is the alignment of the images. I’m going to cheat a little here and pick up the standard style call for images.

Change the post_thumbnail function call in the first loop to the following :

[php]

“alignleft”)); ?>
[/php]

The post thumbnail function allows you to stack extra information in parameters that can be ‘added’ to the code as it’s generated. We have stuffed a reference to a style called alignleft. If you call up the Stylesheet file in the theme editor you can find the definiton of that style (you may have to search for while)

[css]

content .alignleft,

content img.alignleft {

display: inline;
float: left;
margin-right: 24px;
margin-top: 4px;
}
[/css]

This is very similar to our post title example above but this time there is also a reference to the image tag (img).

To finish up we can add the same class to the thumbnail call in the second loop:
Change the post_thumbnail function call in the first loop to the following :

[php]

“alignleft”)); ?>
[/php]

Boxing in the featured story

To make my featured story stand out I’m going to wrap it in a grey box. To start with I’m going to use a DIV to define that extent of the box.

[php]

…the rest of the loop….
[/php]

I’ve added a new DIV tag with an id called FeaturedStory and closed the div after the end of the loop.

If you update the file and looked at the page you should see nothing new. Remember DIV tags don’t show up till you style them.

Open the Stylesheet file in the editor window and scroll all the way down to the bottom. Add the following:

[css]

FeaturedStory {

background: #f7f7f7;
color: #222;
margin-bottom: 18px;
padding: 1.5em;
height: 350px;
}
[/css]

This does the following:

  • Changes the background colour to grey
  • Changes the text colour to a dark grey
  • Pads the bottom of the box with 18 pixels of space
  • Pads the all the way round with 1.5 em of space
  • Sets the height of the box to 350pixels

Save the file and look at the results. You’ll see a box around the featured content.

Conclusion

That’s pretty much it. We’ve pulled in a featured post and thumbnail to go with it. Then we added a second loop to pull in the rest of the posts without duplicating our featured post on the page and added a thumbnail to them. Then we styled the results to align the thumbnail and wrap the featured post in a box to make it stand out.

Along the way we’ve touched on PHP, functions, variables and stylesheets. All of which are play a big part in theme development. But we have done it all with the minimum of alteration to the core theme files.

Some issues

This method is not without its issues. Editing the raw files like this is risky if you forget to back things up. There is also the risk that if the theme is updates by wordpress (as it is from time to time) then your customization will be deleted. But the exercise has been more about some of the basic concepts than a robust solution.

So I hope you found it useful and it made sense. Here’s the finished Main index template file:

[php]

$my_query = new WP_Query('category_name=Featured Story&showposts=1');

		/* Now it loops through the results and displays the content.
		 */

while ($my_query-?>
have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;

/* We load the Page ID in to a variable to check for duplicates later on

  • Then it displays the title as a working link with formatting to
  • match the Twenty Ten template.
  • Then we display the excerpt.
  • Then we finish the loop with the endwhile statement
    */
    ?>

[ “alignleft”)); ?>

](” title=”” rel=”bookmark”>

<?php the_post_thumbnail('medium',array()

if (have_posts()) : while (have_posts()) : the_post();

if( $post-?>
ID == $do_not_duplicate ) continue;
update_post_caches($posts);

/* This line gets the post ID and checks it agains our duplicate variable

  • If it matches it does nothing. If it’s different we display the content
    */

?>

[ “alignleft”)); ?>

](” title=”” rel=”bookmark”>

<?php the_post_thumbnail('thumbnail',array()

[/php]

Don’t forget, you need to update the Stylesheet file as well.

Questions, comments etc always welcome

](” title=”” rel=”bookmark”>

[/php]

The first part of that is:

[html]

](” title=”” rel=”bookmark”>



[/php]

We’ve called the same function but specified the thumbnail image. The results should be something like this (don’t forget you need to add a featured image to your other posts)
<figure id=)

](” title=”” rel=”bookmark”>



[/php]

We’ve added the post_thumbnail function and called the medium sized image (300×300). The result should be something like:

<figure id=)

How to create a wordpress magazine theme using Twenty Ten – Part 3

[Tweet](https://twitter.com/share)**This is part three of a short series outlining how to tweak a wordpress template to get some magazine style functionality....

I've been reading...

[Tweet](https://twitter.com/share)These are my links for September 21st through September 28th: Jonathan Stray » Designing journalism to be used – “News can no longer...

andydickinson.net   Never miss a story from andydickinson.net, get updates in your inbox.