This is part one of a short series outlining how to tweak a wordpress template to get some magazine style functionality. Part two is live!
I’m in the process of updating installations of wordpress for our students to use. In one sense it’s a stop gap measure as we are in the process of commissioning a more “industrial strength” system for them. But even with a new system in place I think we will still leave some courses the option of going the wordpress route. The magazine students for example, love the flexibility (and low level of tech) that design templates offer. It doesn’t seem to have done them any harm in terms of nominations.
When it comes to design, finding a wordpress template you like is half the battle, there are thousands out there. As more people use wordpress to get publications online, magazine style templates have become a popular search and a big growth area for premium template developers.
It’s tempting to pay for a template you like – nothing wrong with that. But it’s not as complicated as you think to get something up and running, out of the box, with very little tinkering. Especially if you build on existing templates. So I thought it would be useful to look at how easy it would be modify the standard Twentyten theme in to something with some magazine functionality.
Hacking around like this is how I learnt a lot of stuff about wordpress and it’s also a way to get your feet wet with a programming language. In this case PHP
To play along with this you’ll need:
- Your own installation of the latest version of the wordpress.org software (as I write this it’s 3.0.1). Sorry wordpress.com won’t do.If you have webspace and your thinking of adding wordpress you could do worse than check out the wordpress codex entry on installing wordpress. Some hosts will offer automated installation of wordpress – very useful.
- A text editor. Even word will do.
This is a screenshot of what we are going to end up with. It has a front page that has a featured post at the top and sections underneath for each category. You’ll also notice that I’ve tinkered around with the header to remove the big image. OK, it’s not going to win any design awards but this is more about exploring the concepts.
Normally you’d plan this kind of thing on paper first. You’d also work on the code in a development environment. An installation of WordPress that only runs on your machine, not the web.
If you’re feeling really brave you can set one up. Here are few resources
- Install a local version of wordpress using the Microsoft Web Platform Installer.(PC)
- Installing WordPress Locally on Your Mac With MAMP (Mac)
- Using XAMPP for local theme development (PC)
I’m going to assume that we dive straight in and edit the template live! I know, bad, bad, bad. All I’m going to say is do so at your own risk.
A word on programming and PHP
WordPress is written in a programming language called PHP. This isn’t a programming tutorial (I’m not going to explain the basics of programming), but there are a couple of important things to know.
You may already be familiar with HTML. You can spot it in the raw code for a webpage because it is contained in pointy – brackets.
<h2>Anything here will appear as a heading two</h2>
In a similar way, you can spot PHP in the raw code for a webpage because it is always between <?php …. ?>. Here’s an example:
<?php the_title(); ?>
But if you look at the source for this webpage in your browser you will only see HTML. Why don’t we see the PHP?
PHP is a server side language. That means the webserver looks at the page and processes any PHP it finds before it sends you the page. When we use PHP as part of wordpress themes we are using it to generate HTML.
When programmers write code they will always look for ways to avoid repetitive jobs. Rather than write the same code every time, they write a function. This is a set of instructions that can be called when needed. The example of PHP above is a function:
<?php the_title(); ?>
Whenever we want to show the title of post we call the function the_title() and the server runs the code needed to get all the right information. The semi-colon is also important. Here’s another example:
<?php the_post_thumbnail('thumbnail'); ?>
This time it’s a function to show a thumbnail for a post. But there is also some content in the brackets. This is a parameter or extra information that the function might need. When the server runs the function to get the post thumbnail it tells the function it wants the thumbnail sized thumbnail. I know, sounds like repetition. We could also say:
<?php the_post_thumbnail('medium'); ?>
That says ‘get the thumbnail but make it medium sized’. In case you were interested, the thumbnail and medium sizes are defined in the media settings of your blog. But more on that later.
There are hundreds of these functions in wordpress. Some are specific to templates, like the examples above, known as template tags. Others do the heavy lifting of making the blog work. We’ll be scratching the surface of the template functions and how they work here but I thought it was worth a little intro.
So we are going to be looking at a little PHP to call some functions to help us modify the TwentyTen template. Hopefully, now, that might statement might make a bit more sense.
How wordpress themes work.
You can get a really good overview of the way themes work from the wordpress codex and plenty of other websites around. A google search for wordpress theme tutorials should give you plenty of options. But let’s break it down in to a few simple ideas.
A wordpress theme is split in to parts:
- the content you want in a structured form
- instructions on the way you want it to look.
This information is held in a number of different files. These are stored in a folder, one for each theme, in the WP_content/themes folder of your wordpress installation. The more complex the theme, the more files there tend to be.
In a basic theme, for example, you will have a file called single.php. That’s the content and structure part. This is a mixture of HTML and PHP. But the way it looks, the colour and style of text, position on the page etc is controlled by a file called style.css. This is a cascading style sheet file.
The Twentyten theme we are going to edit, has 18 content and structure files and four style sheet files. We wont be using all of these for this tutorial. We are only interested in two.
- Main Index Template (index.php)
- Stylesheet (style.css)
Accessing template files
There are several ways we can get at these files:
- Use an FTP client to access the server and edit them directly
- Using the file manager for your website hosting panel E.G. Cpanel
- Use the built in editor function in WordPress.
Any of those will do. But I’m going to work through on the assumption you are using the built in editor.
First thing to do is check you have the TwentyTen theme activated by going to Appearance >Themes. It should show Twenty Ten as the current theme. Then click through to the editor panel (Appearance > Editor).
You’ll see a list of the 18 template files down the right-hand side and an editor window. By default this displays the Visual Editor Stylesheet (editor-style.css). All you need to do is find and click Main Index Template or Stylesheet on the right to load up the files we will be working with.
Permission to edit.
When you look at the bottom of the editor window you may see a warning: – You need to make this file writeable before you can save your changes
This could be the biggest stumbling block of the process. But if you are serious about having a go at theme development, even tweaking like this, it’s worth getting your head round.
To remove the error message you need to set the permissions for the Twenty Ten folder to be 666.
Does that make no sense? You could try:
- How to make WordPress themes writeable which explains how to set permissions using Cpanel and FTP
- The wordpress codex on File Permissions
If you set the permissions correctly, the message should be replaced by a big Update File button.
Some final preparation
From this point I’m going to assume that you have a working installation of wordpress up and running. But before we experiment with the theme we need to have some content to work with. So if your blog doesn’t have posts yet you need to add a few posts to work with. You could do this manually using the lipsum.com, a lorem-ipsum generator and some liberal cut and paste for content. There are also a number of random content generator plugins available. For this exercise I used demo data creator.
We will also need to create some categories and assign the posts across the categories. I’ve used the following for this demo:
- Featured Story
Once you have done that we are ready for Part 2 tomorrow, where we will start to edit the front page to get that magazine look.
As always, feedback and suggestions always welcome