Build Your Site with WordPress : Tutorial

Need to know
Before you run off to start creating a WordPress-based site, there are a few things you need to remember.
First, WordPress is best for a site that is regularly updated, so it’s perfect if a business blog or newsfeed is part of your plan, but overkill if all you want is a few static pages.
Thirdly, while WordPress’s core features are impressive on their own, they aren’t tailored for businesses. It doesn’t have any ad management features, for instance, nor does it have any site statistics built in. Again, this is easily remedied—WordPress has a huge database of plugins that’ll add these functions to your site, and installing them is embarrassingly easy.
Finally, before you begin setting up WordPress, you’ll need to have some information handy:
- A MySQL username and password for your site (you can get this from your site’s host)
- The ability to access your site’s files via FTP
- The latest version of WordPress, from wordpress.org/download.
Before beginning, create a new database in MySQL – this will hold all the content and information for your site. Unzip the WordPress archive that you downloaded, and you’ll see all the files you need inside a folder called wordpress. Rename wp-config-sample.php to wp-config.php. Open the file in any text editor, and enter your database name, username and password under “MySQL Settings”.
Once you’ve got your administrator password, you can log into your site’s Dashboard, which gives you a quick overview of what’s happening on the site.
How the content works
When talking about content in WordPress, we use four terms – posts, pages, categories, and tags.
Posts are the most basic units of your site: every time you add new content to the site, you do it as a post. To add a new post, go to Posts > Add New in your dashboard. You can also add excerpts to posts, which are summaries of the posts’ content. On your site’s main page, posts appear newest first.
Pages are similar to posts, but are for static content – an “About Us” page, for example. They fall outside the normal structure of your site, and unlike posts, don’t follow the newest-first order. You also can’t put them in categories.
And finally, you can add tags to posts, which are key terms that describe the posts. Search engines pick up these terms when they’re crawling sites, so if you’re starting a company blog, tagging your posts is always a good idea.
Without customizing your theme, however, your content is still going to look like a blog.
Customizing the site
Once you’ve found a theme you like, download and extract it to your hard disk, upload the theme folder to wp-content/themes/ on your site, and go to Appearance in the dashboard to activate the theme. Most WordPress themes will give you one or more sidebars (which may or may not be on the sides), to which you can add widgets, such as a calendar, a list of categories, and so on. To add widgets to your sidebars, go to Appearance > Widgets, and drag the widgets you want into the sidebars you want them in.
If the pre-made themes don’t meet your needs, you can exploit the almighty WordPress Loop to create one of your own.
Getting Started With A Theme
There aren’t enough pages for us to get into the nitty-gritties of theme design, but you need two files to get started: a style.css, that will contain all the CSS styles for your theme, and index.php, which will be the template that all your pages are based on. At the heart of it all is this bit of code, called the WordPress Loop
<?php if ( have_
posts() ) : while
( have_posts() ) :
the_post(); ?>
<!--this is where
you display content-->
<?php endwhile;?>
This code gets your posts from the database, ten at a time, ready for you to display as you want it. For example, let’s say you have a three-column layout, and the HTML looks something like this:
<div id=”column-
1”></div>
<div id=”column-
2”></div>
<div id=”column-
3”></div>
Let’s say that you want posts from the News category in column 1, the titles of all your posts in column 2, and a sidebar that you can stick widgets into in column 3.
First, the news. Here, we’ll use the query_posts() function, which lets you change the way that WordPress fetches posts from the database.
<!--start a loop in
column-1 for news-->
<div id=”column-1”>
<?php
query_posts(‘category_
name=News’); //
restrict only to the
News category
//start
the loop
if (
have_posts() ) : while
( have_posts() ) :
the_post();
?>
<h1><?php the_
title();?></h1>
<div
class=”excerpt”><?php
the_excerpt();?></div>
<a
href=”<?php the_
permalink();?>”>Read
More..</a>
<?php
endwhile;?>
</div>
As you can see, WordPress gives you functions that are quite self-explanatory: use the_title() to display the title, the_excerpt() to display the post’s excerpt (or the_content() to show all the content), and so on.
Column 2 is much the same:
<div id=”column-2”>
<?php
//start
the loop
if (
have_posts() ) : while
( have_posts() ) :
the_post();
?>
<h3><a
href=”<?php the_
permalink();?>”><?php
the_title();?></h3></
a>
<?php
endwhile;?>
</div>
As far as index.php is concerned, column 3 is simple:
<div id=”column-2”>
<?php get_
sidebar();?>
</div>
But this means your theme now needs two more files: sidebar.php and functions.php. Create a new file called sidebar.php and enter this:
<ul id=”sidebar”>
<?php if (!function_
exists(‘dynamic_
sidebar’) || !dynamic_
sidebar()): ?>
<li>
This sentence will appear if you haven’t chosen any widgets.
</li>
<?php endif; ?>
</ul>
This makes your sidebar dynamic, and hence capable of holding widgets. The second part of this activity is registering the sidebar. Create a new file called functions.php, and enter this bit of code:
<?php
if ( function_
exists(‘register_
sidebar’) )
register_
sidebar();
?>
That covers the most essential (and probably the most useful) aspects of writing a theme. Obviously, the job doesn’t end here. You should create templates for categories, single posts, pages, and any type of content that you want to make specific designs for.
Recommended WordPress Plugins
Ultimate Google Analytics
Track how much traffic you’re getting, where that traffic is coming from, and how many sites are linking to you.
OIOpublisher
This one’s paid ($47), but might be worth it—it’s an insanely advanced ad manager, even automating the ad sales process.
WP e-Commerce
Lets you turn your WordPress site into an online store.
Theme My Login
Makes registered users see a special login and profile page that matches your theme, rather than the WordPress defaults.
Breadcrumb NavXT
Lets you add breadcrumbs (Home › Category › Post, for example) to your templates.
Microkid’s Related Posts
Adds related links to your posts manually, so you don’t have to rely on tags or keywords to determine which posts are related.
OnePress Framework
A theme “framework”, which you can use as the basis for designing an elaborate theme of your own. Nearly every area is widget-ready, and it even comes with a few widgets of its own. As a bonus, OnePress also comes with the ability to integrate your WordPress site with a phpBB forum.
is_human()
Have users verify their humanity by answering questions or solving an equation (probably the most effective way to avoid spam registrations)
Developing your own theme gives you much tighter control over the way your posts – and ads – are displayed, and even if you’re just modifying a theme you downloaded, it’s worth your time to see what the Loop is capable of. For more, visit the exceptionally well-documented WordPress Codex at codex.wordpress.org