WordPress Theme Design – Theory In Action

Below are two screenshots. The first was my mockup for the theme that's part of the "WordPress Theme Design" series, the second is the result of a little work I did tonight.

Between doing the heat, an excessively busy work week I'm a bit overwhelmed tonight so I thought I'd share two screenshots. One of the two shots below is the original concept art for a new theme while the other is one hour worth of coding. Check them out and let me know what you think.

theme2.png

Black & Yellow Thumbnail

There's still some tweaking to be done but things are coming along nicely.

.htaccess – Blocking sites by URL

  • Posted On: May 10th, 2007
  • Filed Under: Web Design

Last week I found the need to block incoming traffic from a particular site. While the author was kind enough to remove the links to my page when I first discovered the issue I was quick to block the traffic just to be safe.

The following code can be placed in your .htaccess file to block incoming traffic by URL.

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} FirstSite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} SecondSite\.co\.uk
RewriteRule .* - [F]

The code above blocks traffic from two separate URLs. [NC, OR] should follow every line after the first but excluding the last in order to block more than one site.

WordPress Theme Design – Body and Sidebar

Leading up to now we've managed to build template files for our header, footer and stylesheet. All that's left, right now, is to build template files for our index.php and sidebar.php files. For the time being we're going to keep these files as simple as possible - just like our header, footer and stylesheet.

After this post is complete we're one post away from our super basic WordPress template. Let's get started.

The Sidebar.php File

For now we're only interested in setting up the basic sidebar so we'll skip over adding any content to it. All the file really needs to contain is some basic text just to signify the sidebar itself. Later on we'll talk about floating the sidebar and getting it exactly where we want it - that's still a short while away though.

For now you simply want to include some basic text in your file - just "This is the Sidebar" will do.

The Loop and Index.php

The WordPress Loop is the code that really controls any listing of your posts. Whether it's a category page, post, or Page you'll be using the loop to call your posts. Most of the hard work is all behind the scenes - you just need to familiarize yourself with the basics. For now we're interested in running a very basic version of the loop so we'll keep it simple. When we start talking about customizing a post we'll get into more detail.

The Loop in Action

Below you'll see a basic version of the WordPress Loop. We're not going to do anything fancy with it right now - just set it up to display posts. The code below will display each post's title as well as the post's content. Simply add the following text to your index.php file and your loop will be ready.

<?php if (have_posts() : while (the_post()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; else : endif; ?>

The code above is a relatively simplified Loop. When executed it will simply display all post titles and the post content. It won't look spectacular but it will do the job.

Calling the other Templates

At this point our basic starting theme is almost done. In order to bring everything together we need to include a few more lines of code. WordPress offers some simple tags for calling our header, footer and sidebar which we need to add to our index.php in order to get things running.

Thankfully the tags we need are really easy to remember - it's just a case of putting them in the right place. In an un-styled page we want our content to behave a certain way. The basic page structure requires that our header and footer always start and finish the page so we know right off the bat that they'll lead and close our index.php file.

Besides our header and footer we also need to add the sidebar. Bare in mind that your content should always precede your sidebar text. Recognizing this your sidebar should always be called after your content but before your footer - here's how it'll look:

<?php get_header(); ?>
  Loop Goes Here
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Once you've done this boot up your version of WordPress sandbox and you're ready to go. Tomorrow we'll begin dissecting playing around with the theme's color and typography.

WordPress Theme Design – style.css

In this post we're just going to discuss some of the basics for putting together a WordPress stylesheet. When we get into the specifics of the theme pictured at the start of this series we'll talk about some of the CSS needed, for now we're just looking at some basics for creating a stylesheet that can be used when starting any new theme.

WordPress has a very basic set of rules for defining a theme's stylesheet. If you're interested in starting to design your own themes it might help to create a few template files that can be used anytime you want to start fresh. In the last post I listed a few files that you could create for getting started - in this post we'll start filling out the style.css file to get it ready for later customization.

The Required Header

CSS doesn't specifically require any type of header when you're putting together a stylesheet - WordPress, however, does. Besides simply allowing you to use your theme, the header is great for setting up an organization structure for your stylesheet. The basic WordPress header looks like this:
/*
Theme Name:
Theme URI:
Description:
Version:
Author:
Author URI:
*/

It's all pretty straightforward and simply adding the text above to your style.css file is enough to get WordPress to accept your theme.

WordPress Theme Design – Header and Footer

Today and tomorrow we'll take a closer look at building some template files for your first WordPress theme. The files we'll be constructing are the bare basics of your theme and can be recycled anytime you want to start something new. With an emphasis on the basics we'll look at the files suggested in our previous post on Getting Started with WordPress Theme Design and by tomorrow night (roughly 4 posts away) we'll have our first test theme ready.

In this post we'll work briefly with the header.php and footer.php files. We'll create some basic structures in the files and get them ready for when we really take on the brunt of actually designing the page.

Let's start with the Header. Read the Rest of this post