Sai Gopal Wordpress Blog

saigopal wordpress blog

Saigopal's website

Saigopal's website

My Daughter Website

Weebly

Palwow

Freelance Jobs

Friday, May 28, 2010

changing the look of your wordpress blog

Changing the Look of
Your Blog
This chapter is about the reader’s view of your blog. It is about what your visitors see and how
they interact with your blog. That interaction, or experience, is important in ensuring your visitors
get the most from your site. If the experience is positive—they find what they want, and
they can interact easily and successfully—then they will want to come back. A good design will
drive that experience.
It is also about the aesthetic experience, too. The look of your blog, especially the first page,
must either fit the users’ expectations or surprise them in a positive, pleasing way. If you and
your community are discussing fan fiction for a Gothic TV horror show, they want a dark, slightly
sinister, experience. If you are all about craft fun for preschool children, you’ll want to present
a bright, airy, fun face to your readers (but not childish, since the parents are your audience).
The face of your blog—its outward appearance—is provided by the theme in use on your
blog. In this chapter, you’ll learn how to activate themes in WordPress, find and install new
themes, and modify themes. But first, let’s start with the purpose of your theme.
Using Themes to Communicate with
Your Audience
How do we communicate? Let me answer that question with another question. Have you ever
had a phone conversation with a person speaking in a monotone voice? If so, you’ll understand
that it’s not very engaging. You might have even found yourself overemphasizing your own
parts of the dialogue just to compensate!
Compare this situation to a face-to-face discussion with multiple participants. You may
have witnessed first hand the complex body language taking place throughout the conversation
as people start to use their hands to convey emphasis, or move their body between passive
and aggressive stances depending on their activity in the group. Now consider a lecture given
by a speaker at a conference. A good presentation is enhanced by visuals, moving parts, and
engaging with the audience. It’s as if the speaker understands the audience.
433
C H A P T E R 16
■ ■ ■
■Note Andrew Chak, in his book Submit Now: Designing Persuasive Websites (New Riders Press, 2002)
defined visitors to web sites in three different ways of moving around the site.Wanderers encounter the site
with no real purpose in mind, looking for something to catch their attention. Finders are looking for something
specific or help to find it, even though they don’t know exactly what they want. Learners are looking
for some information to learn something new.
When visitors come to your site, it needs to communicate in more than text alone. Word-
Press doesn’t hinder you in your quest to communicate with visitors. It enables you to configure
your blog to add images, define an organization, and use a style for each page consistently if the
whole site maintains a single theme or idea, or individually if each page has a theme of its own.
A simple example is to define each category to have unique colors and images while maintaining
a consistent arrangement on each page. In this chapter, I’ll show you how to use WordPress
themes to have your blog’s appearance achieve this communication with your audience.
A WordPress theme is like a template. WordPress inserts the posts you write, the comments
your readers leave, the links you create, and other information into the page dynamically. Themes
consist of a number of PHP files and a style sheet.
Before going any further, let me assure you that you do not need to understand the internals
of how a theme works or how it’s managed by WordPress to use it. Adopting a theme can
be as simple as uploading it to your blog and enabling it in the Themes tab of the Presentation
page. On the other hand, if you want to start investigating a theme with the intention of learning
from it or modifying it, you can do that, too. I will show you how to do that later in this
chapter, in the “Modifying an Existing Theme” section.
Selecting an Installed Theme
WordPress comes with two built-in themes. The Default theme, based on Michael Heilemann’s
Kubrick theme, is shown in Figure 16-1. It is a fixed-width layout centered in the browser window.
The other built-in theme is the WordPress Classic theme produced by Dave Shea for
WordPress 1.2, shown in Figure 16-2. This is a flexible theme that stretches to fill the width of
the browser.
434 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 435
Figure 16-1.WordPress Default theme
Figure 16-2.WordPress Classic theme
To select one of your installed themes, log in to the administration pages and click Presentation.
You will be presented with the theme selection page, as shown in Figure 16-3. This
page shows you all the installed themes and highlights the currently active theme. Click the
Select button of the theme that you wish to use, and then click View site at the top of the page.
Try that now to switch to the Classic theme, and you will see your blog content’s presentation
change (see Figure 16-2).
You can see how easy it is to completely change the style of your blog. Both of the built-in
themes include a variety of information in their sidebars, such as lists of categories, links to
archives, meta-information, and so on.
Adding New WordPress Themes
Adding themes to your WordPress installation is easy. You just download a theme and install it.
After the theme is installed, it will be listed on the Themes tab of the Presentation page, where
you can activate it, as described in the previous section.
Finding Themes
You can find lists of WordPress themes many places, including the following sites:
• The most comprehensive list at the time of writing is on WordPress’ Codex at
http://codex.wordpress.org/Using_Themes/Theme_List.
436 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-3. Selecting a theme
• A small selection of themes is highlighted at http://wordpress.org/extend/themes/.
• A large collection of themes is available at Alex King’s WordPress Themes Competition
site (http://www.alexking.org/index.php?content=software/wordpress/themes.php).
That competition is over now, but all of the entries are still available for viewing and
downloading.
In all, currently more than 300 themes are available for download from these sites. Most
of them are free to use with no restrictions. Some might require a link back to the designer of
the theme. Also, a number of designers will sell you a WordPress theme or design one to your
exact specifications—for a fee, of course.
Quite a variety of different styles are available: common two-column layouts with a wide
main column for posts and a second narrower column for lists, links, and so on; several threecolumn
themes; some four-columns ones; and a small number of themes with more unusual
shapes. The appearance of all these themes covers a wide range—from business-like to just
plain weird!
I mentioned earlier that you should style your site to suit the main subject of your blog.
Consider the theme shown in Figure 16-4, which is a Franz Ferdinand theme from Francey
(http://francey.org/linkware/15/), a talented young college student who produces web
designs for fun. This is a dark theme in a style suited to a music fan site.
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 437
Figure 16-4. Dark of the Matinee theme by Francey
As another example, take a look at the Juicy theme by Joni Mueller of Web Jones Designs
(http://webjones.org/), shown in Figure 16-5, which I spotted on Alex King’s site (http://
managedtasks.com/wpthemes/blog/index.php?wptheme=Juicy). This theme would perhaps be
suited to a blog about healthy eating. Its clean, fresh look and pertinent imagery would help
keep your readers focused on the subject.
■Tip Some designs for older versions of WordPress are available around the Web, particularly
WordPress styles for version 1.2, many of which are listed at Alex King’s old competition site http://
www.alexking.org/index.php?content=software/wordpress/styles.php. These are not compatible
with the current version 1.5 and need to be converted. A straightforward conversion is fairly painless, and
you can find details of that process on the WordPress Codex at http://codex.wordpress.org/
Upgrade_1.2_to_1.5#Upgrading_Old_Templates_-_Easy.
438 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-5. Juicy theme from Web Jones Designs
Installing Themes
Once you have chosen a theme, you need to install it. Here are the steps:
1. Find the download site and download the zip file.
2. Unzip the theme zip file to your local machine.
3. Upload the files to your server, placing them in the wp-contents/themes folder.
4. Go to the Presentation administration page of your blog and activate the theme (see
Figure 16-3, shown earlier in this chapter).
If a theme requires a particular plug-in that you don’t have installed and the theme author
hasn’t coded it well, you may get an error message (see Figure 16-18 later in this chapter). If
this happens, activate another theme that you know does work and check the readme.txt file
or the theme’s documentation page (there should be a link to it on the Presentation admin
page). The readme file may mention any requirements for the theme or any restrictions on usage.
If you still want to use the theme, download and install any required plug-ins before activating
the theme again. (Refer to Chapter 15 for instructions on installing plug-ins.)
Modifying an Existing Theme
If you cannot find a theme that matches your requirements, you could create your own, but
that’s not a trivial task. Rather than create a new theme from scratch, it is often quicker to take
an existing theme similar to what you want and modify it, assuming the license allows that. This
is the approach I describe here. First, let’s look at the components of a theme.
Examining a Theme’s Components
A theme consists of two or more files. At the very least, it requires a CSS style sheet named
style.css and a PHP template named index.php. The style sheet must contain a specially
formatted comment at the beginning of the file. This comment identifies meta-information
about the theme, such as a name and description for the theme, version number, URL for the
theme, and so on. Figure 16-6 shows this comment for the WordPress Default theme.
The PHP file contains the HTML and WordPress tags to display your content. This file
contains what WordPress calls The Loop, which is a fairly short but important piece of PHP
code that is the heart of your blog page. This code displays the title and contents of your blog
posts, as well as information related to it. It also displays a count of the comments a post has
and a link to the comments themselves.
All the rest of the information displayed on a typical blog page—the blog title, links in a
sidebar, archive links, and so on—is peripheral to The Loop. Most of this other information is
displayed by calls to template tags.
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 439
Template tags are small pieces of PHP code (typically one line of code) placed in your
template. These tags do a variety of work. Here are just a few examples of what template tags
can do:
• List the categories in your blog. This list includes links to make your blog display all the
posts in each particular category.
• List your archives by month, by week, or individually.
• Create a calendar on your page, complete with links to stories for each day and links to
move the visitor backwards and forwards through the history of your blog postings.
• Change the title of your web page based on the current story or current category.
All these template tags produce XHTML, not colors, borders, or columns. In other words,
the tags make the real content of your blog, marked up semantically, with meaning. The CSS
applies the look to this page, adding the colors, positioning different elements into columns,
and so on. This allows you to deliver the content in a number of ways without changing the
content itself.
■Tip As an example of the variety of ways you can deliver the same content in very, very different ways,
pay a visit to the CSS Zen Garden (http://csszengarden.com). This is a site put together to demonstrate
the design capabilities of CSS. The site has hundreds of different themes in a vast range of styles from simple,
business-like designs, to eastern-flavored works of art, through punk-styled graffiti-like pieces. But
every single version of the site uses exactly the same HTML content!
WordPress goes further than many theming and skinning systems. It can automatically
use special template files in appropriate circumstances if it finds them. For example, if you are
440 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-6. Stylesheet meta-information
displaying a single post and the file single.php exists in your current theme directory, Word-
Press will use that template. This allows you to present single posts with a different layout.
Similarly, a file called page.php will be used to display pages. For example, you might decide
to use the full width of the browser for your in-depth pages with more content and not display
the sidebar.
In this section, I will take you through some adjustments to a theme. You will see how to
remove elements you don’t want and add extra information you do want. You will also learn
how to adjust the CSS to make things appear differently, without needing to change the HTML
generated from the template.
Installing and Copying the Theme
First, you need to obtain the theme that you want to modify. For the original theme to use in
this chapter’s example, I have chosen the c3ro mask theme by C3ro, created by Chris Carlevato
(http://c3ro.com/themes/), shown in Figure 16-7. This is a beautiful, three-column theme
with a graphical masthead and a fading background. It is a little unusual in that it has its two
narrow informational columns, both on the right.
I made a couple of changes to the original theme to make it valid XHTML, as standards
compliance is an important part of WordPress. The validated theme is available from the
Source Code area of the Apress web site (http://www.apress.com), as c3romask-xhtml.zip.
Use this as your starting point.
After you download c3romask-xhtml.zip, unzip it into a folder call c3romask. Then upload
the folder and its contents to your wp-content/themes folder. Go to the Presentation administration
page and select the c3ro mask theme to activate it. If you view your blog now, it should
look like Figure 16-7.
So that you can compare the before and after versions of the theme, you will make
changes to a copy of the theme. On your local machine, in the place you unzipped the original
theme, rename the c3romask directory to c3romask2. (You could instead copy the directory and
not rename it in order to retain the original code on your local machine for later comparison
should things go drastically wrong.)
You will also need to edit the style.css file to change the name defined in the file. If two
installed themes have the same name, even if they are in different folders, WordPress gets confused.
See Listing 16-1 for the new header comment.
Listing 16-1. New Theme Meta-Information in style.css
/*
Theme Name: c3ro mask 2
Theme URI: http://c3ro.com/themes/
Description: A modified version of c3ro's mask theme
Version: 1.0
Author: Mike Little (after c3ro http://c3ro.com/)
Author URI: http://building-online-communities.com/wordpress/
*/
Upload this new folder with the modified style.css into wp-contents/themes and check
the Presentation page. You should now have the c3ro mask and c3ro mask2 themes listed.
Activate the c3ro mask 2 theme.
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 441
Modifying Theme Images
To change the tone of the theme, choose a different header graphic. You can use any image or
images you find to convey the appropriate impression about your blog. You could take a photo
yourself or buy an image from one of the many photo agencies on the Web. For this example, I
thought the group of horses shown in Figure 16-8 seemed to convey the idea of a community.
442 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-7. The original c3ro mask theme
To replace the header graphic in the theme, I cropped the image to match the dimensions
of the original header graphic. I also overlaid the blog name onto the image. The original theme
header deliberately left that area blank for the same purpose. My header image is shown in
Figure 16-9.
After you are happy with your main header image, copy it to the same name as the theme
header image, overwriting the original. The theme now automatically uses your new version of
the header image.
You can continue to modify the other background images that accompany the theme,
again copying over the originals. I re-created them using colors from the new masthead image
to blend with it. Finally, I tweaked the CSS style sheet to use the same colors from the header
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 443
Figure 16-8. A new base image for a theme
Figure 16-9. Cropped and modified image ready for the theme
image for highlights and so on. See Figure 16-10 for the progress so far. You can download this
version of the theme, c3romask2-step1.zip, from the Source Code area of the Apress web site
(http://www.apress.com).
Changing the Template
If you want to make modifications to your theme files, you can edit them in WordPress’s Theme
Editor, as long as the theme files are writable by the web server process (see the “Setting File
Upload Options” section in Chapter 14). To activate the Theme Editor, go to the Presentation
administration page and click the Theme Editor tab. Make sure that the theme you want to edit
(c3ro mask 2 in this example) is selected in the drop-down list.
Alternatively, you can edit the theme files on your machine with your favorite editor and
upload them when you are ready. In both cases, you will want to make a backup copy, in case
something goes wrong.
444 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-10. The new theme with all images and colors in place
In this example, you will remove the list of buttons underneath the calendar and add a list
of news stories using the RSS Link List plug-in introduced in Chapter 15. To remove the buttons
from the rightmost column, choose the Main Template index.php from the drop-down list of
theme files on the right side of the page. When that file loads, find the section of index.php that
begins
The additions in Listing 16-7 are standard WordPress template tags. The call to
wp_register() produces a link to the registration page, but it does so only if registration
is enabled. If you are logged in, however, it produces a link to the administration pages.
448 CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG
Figure 16-12. The improved list of links
The call to wp_loginout produces a link to the login page if the current visitor is not already
logged in, and a logout link if the visitor is logged in.
Next, add the CSS rules from Listing 16-8 to the end of the style sheet. This will ensure the
display of the links matches that of the other parts of the sidebar.
Listing 16-8. CSS Rules for Login and Register Links Added to style.css
ul#contribute {
list-style-type: none;
margin:0;
padding-left: 10px;
}
ul#contribute li {
margin-top: 4px;
margin-left: 1em;
text-indent: -1em;
}
Figure 16-13 shows how your register and login links should appear, and Figure 16-14
shows the site admin and logout links.
CHAPTER 16 ■ CHANGING THE LOOK OF YOUR BLOG 449
Figure 16-13. The register and login links Figure 16-14. The site admin and logout links
Adding a Recent Comments Plug-In
Now you will install another plug-in, which will list a number of the most recent comments to the
blog in the sidebar. This is great mechanism to keep your readers interested. It allows them to see
which topics are still being discussed, and thus is an added incentive to keep reading those topics
and to continue to get involved. Real conversation about a shared interest between your readers
is the lifeblood of an active online community.
The plug-in is the Customizable Comment Listings plug-in by Scott Reilly. You can download
this plug-in via Scott’s site at http://www.coffee2code.com/archives/2005/03/30/
plugin-customizable-comment-listings/.
Download, install, and activate the plug-in using the procedure covered in Chapter 15.
Read through the comprehensive documentation on Scott’s site.
Next, add the code shown in Listing 16-9 (from one of the examples in the plug-in’s
documentation) to the index.php template file, just before the contribute section. The single
parameter 5 tells the plug-in to list only the five most recent comments.
Listing 16-9. Code to Insert into index.php Immediately Before the Contribute Links

No comments: