Tag-Archive for » Theme «

How to Create a Tumblr Theme (Code Structure)

As we have previously seen, Tumblr allows its uses to create custom themes giving the owner of a tumbleblog the ability to truly customise their tumbleblog to be their own. While tumblr coding is fairly easy to pick up compared to other more complex blogging systems, I want to give you an insight into the code and structure we are going to be deploying next time around when we set about converting a psd to tumblr.

Understanding the basics

Before we get stuck into the Tumblr code itself, you need to first know what a Tumblr theme looks like. Gone are the gazillion template files of other CMS’s; Tumblr uses one and only one. A single page of html, with the css and scripts in the head of the file is all you’ll need.

Now that you know how a theme looks, we are going to look at two simple concepts that make our single html page into a fully dynamic tumblr blog. These are variables and blocks.

Variables are exactly what the name suggests. Aplace-holdertag that our data is dynamically inserted into. They are used all across the theme in anything from titles to our dates. They use curly brackets and look like this :

Blocks on the other hand are asort ofstep up from variables. They are used to display chunks of html and variables for differentoccurrences, e.g. for each different kind of Tumblr post. They can even be used conditionally to display stuff such as next and previous page links. Like variables, blocks use curly brackets, but are defined as ablock, and open and close in a mannersimilarto htmlelements.

Put these blocks and variables to user together within html, and you will end up with a theme!

Html head

As always in Html, there are several pieces of information you are going to want to include within the head of your html document, and Tumblr does not let us down. It provides us with several variables that can be deployed with great ease.

{Title} – The html safe title of your blog

{Meta Description} – An html safe description of your blog for use within the meta tag

{Favicon} – A dynamically generated favicon url from your portrait photo

{RSS} – The url to the RSS feed of your tumbleblog

<head>
	<title>{Title}</title>
	<link rel="shortcut icon" href="{Favicon}">
	rss+xml" href="{RSS}">
	<meta name="description" content="{MetaDescription}" />
</head>

Basic Variables

Before we start displaying our posts and content, there are certain things we are going to want to display around our tumbleblog. Most of these are likely to appear in our header, such as our blog name, and logo / photo. Here are some of the variables that make this possible.

{Title} – The html safe title of your blog

{Description} – The description of your blog which may include html

{PortraitURL-64} - The url to yourportraitpicture. Different sizes areavailable(16, 24, 30, 40, 48, 64, 96, 128)

<div id="header">
	<h1>{Title}</h1>
	<p>{Description}</p>
	<img alt="{Title}" src="{PortraitURL-64}" />
</div>

Display Posts

Now that we have setup theeasy stuff with some basic variables, it’s time to get stuck into the more dynamic posts which are rendered with the help of both blocks and variables. The posts block is placed in the area that all our different types of posts will be displayed.

Within our posts block, we can start to branch out into our many different kinds of posts. Each of these are shown below.

{block:Text}{/block:Text} – Displays Text posts

{block:Photo}{/block:Photo} – Displays Photo posts

{block:Photoset}{/block:Photoset} – Displays Photoset posts

{block:Quote}{/block:Quote} – Displays Quote posts

{block:Link}{/block:Link} -DisplaysLink posts

{block:Chat}{/block:Chat} – Displays Chat posts

{block:Audio}{/block:Audio} – Displays Audio posts

{block:Video}{/block:Video} – Displays Video posts

{block:Answer}{/block:Answer} – Displays answer posts

Each different type of post has several different types of variables and further blocks that arerelevantonly to that type of post, but there are several variables that are likely to be used in ever post such as the link, and tags.

{Permalink} – The exact url for a single post

{ShortURL} – The sharing friendly short url for a single post

{PostID} – The unique numeric post ID for a single post

{block:Posts}
...
	{block:Text}
	<div>
		{block:Title}
		<h2><a href="{Permalink}">{Title}</a></h2>
		{/block:Title}
		<div>
		{Body}
		</div>
	</div>
	{/block:Text}
...
{/block:Posts}

Moving down into each specific post type itself, variables and blocks become far more specific to the post type. I won’t go into any of them as there’s a lot of them to remember, but if you feel you want to take a look at the them now, then here’s where to learn more.

  • Text posts
  • Photo posts
  • Photoset posts
  • Quote posts
  • Link posts
  • Chat posts
  • Audio posts
  • Video posts
  • Answer posts

Next / Previous Links

The other majorly important feature you are going to want to include is pagination for your posts and pages; in both cases Next and Previous links, and lo-and-behold, Tumblr caters for both with variables and blocks.

An initial block is used to conditionally display the full pagination html, with two further conditional blocks to conditionally display each Previous and Next link. Finally, two variables are used to display the relevant destination url.

Single posts have different blocks and variables for pagination than those for pages, so here they are.

For pages, these are the blocks and variables used for pagination.

{block:Pagination}{/block:Pagination} – Only displays if there are previous / next pages to link to

{block:PreviousPage}{/block:PreviousPage} – Only displays if there is a previous page

{block:NextPage}{/block:NextPage} – Only displays if there is a next page

{PreviousPage} - Url for the previous page

{NextPage} – Url for the next page

{block:Pagination}
<ul>
	{block:PreviousPage}
	<li>
		<a href="{<span class=">PreviousPage</a><a href="{<span class=">}">Previous</a>
	</li>
	{/block:PreviousPage}
	{block:NextPage}
	<li>
		<a href="{<span class=">NextPage</a><a href="{<span class=">}">Next</a>
	</li>
	{/block:NextPage}
</ul>
{/block:Pagination}

Similarly, for posts, these are the relevant blocks and variables.

{block:PermalinkPagination}{/block:PermalinkPagination} – Only displays if there are previous / next posts

{block:PreviousPost}{/block:PreviousPost} – Only displays if there is a previous post

{block:NextPost}{/block:NextPost} – Only displays if there is a next post

{PreviousPost} - Url for the previous post

{NextPost} – Url for the next post

{block:PermalinkPagination}
<ul>
	{block:PreviousPost}
	<li>
		<a href="{<span class=">PreviousPost</a><a href="{<span class=">}">Previous</a>
	</li>
	{/block:PreviousPost}
	{block:NextPost}
	<li>
		<a href="{<span class=">NextPost</a><a href="{<span class=">}">Next</a>
	</li>
	{/block:NextPost}
</ul>
{/block:PermalinkPagination}

Further Reading

There are several further features that you may want to add into your theme, and as usual Tumblr caters for many of them. However, I simply wanted to go over the basics here, and not flood you withunnecessaryinformation while learning. If you do want to continue reading, take a look at the official Tumblr documentation for these features listed below.

  • Dates
  • Notes
  • Tags
  • Group Blogs
  • Day Pages
  • Search
  • Following
  • Likes

What’s up Next?

Next up is a tutorial that will teach you how to take a psd design of a tumbleblog, and turn it into a fully fledged Tumblr theme. Keep your eyes open for that, but for now, here’s a sneak peek at what we’ll be creating!

Click on the image to see Full Size

How To Create An Options Page For Your WordPress Theme

WordPress is one of the most popular Content Management Systems. Also WordPress isa CMS of choice for many web developers Its relatively easy to use, but can be made even simpler when you include an administration panel for users when making themes. Additionally, themes buyers find the options panel too easy to use rather than having to open up the PHP template files and fiddling with the code.

Today we will be incorporating an options panel for the WordPress Classic theme. The methods you will learn will allow you to very easily integrate it into an existing theme youre working on.

Setting The Files :

The theme that we will be working on is the classic theme provided by wordpress. You can find it on wp-content/themes folder. You should see the following files:

  • index.php
  • functions.php
  • comments.php
  • footer.php
  • header.php
  • rtl.php
  • sidebar.php
  • style.css
  • screenshot.png
  • An images folder with two files

Most of our work will be done within the functions.php file.

Now go to your wordpress admin panel then go to Appearance>Themesand activate the classic theme.

Working on functions.php :

Begin by opening up functions.php in your code editor of the classic theme (wp-content/themes/classic/functions.php) then insert the following code :

<?php
$themename="Classic Theme";
$shortname="ct";

I added two variables the first one reffers to the name of the theme and the second is the shortname : You can choose any name for these two variables but don’t forget to select significant names because you will be using them later.

Now let’s start adding some options for our theme :

$options = array (
 array( "name" => $themename." Options",
       "type" => "title"),
   array( "type" => "open"),
 array( "name" => "Color Scheme",
           "desc" => "Select the color scheme for the theme",
       "id" => $shortname."_color_scheme",
           "type" => "select",
       "options" => array("blue", "red", "green"),
       "std" => "blue"),
 array( "name" => "Logo URL",
       "desc" => "Enter the link to your logo image",
       "id" => $shortname."_logo",
       "type" => "text",
       "std" => ""),
 array( "name" => "Homepage header image",
       "desc" => "Enter the link to an image used for the homepage header.",
       "id" => $shortname."_header_img",
       "type" => "text",
       "std" => ""),
 array( "name" => "Footer copyright text",
       "desc" => "Enter text used in the right side of the footer. It can be HTML",
       "id" => $shortname."_footer_text",
       "type" => "text",
       "std" => ""),
 array( "name" => "Google Analytics Code",
       "desc" => "Paste your Google Analytics or other tracking code in this box.",
       "id" => $shortname."_ga_code",
       "type" => "textarea",
       "std" => ""),
    array( "name" => "Feedburner URL",
       "desc" => "Paste your Feedburner URL here to let readers see it in your website",
       "id" => $shortname."_feedburner",
       "type" => "text",
       "std" => get_bloginfo('rss2_url')),
    array( "type" => "close"));

Here the variable “option” contains a big array which also contains other child arrays. Each child array holds an option.

The first array reffers to the title of the page ( In our case it’s ‘Classic Theme Options’ ). Every time when we want to add a new option we have to declare an array with a type and give it the name we want.

You can take a look at the options specified below :

  • name: The name of the input field.
  • desc: A short description explaining what it is to the user.
  • id: the id of the field, prefixed by the shortname. It will be used to store as well as access the options.
  • type: the input type select, text or textarea
  • options: used to declare an array of options for a select type input.
  • std: the default input value, used if no other input is given.

Now we have our options ready but how can we view them ? Add the following pieces of code to the functions.php file:

function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($options as $value) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $value['id'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_menu_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}

Here I declared a function with a name of “mytheme_add_admin”. This function is used for updating options : If the options are saved, then all the options are updated with their new values. If the options are being reset (indicated by another hidden variable with a value reset), then all of the options are deleted. The last line adds a theme page( add_theme_page ) in Appearance box and it calls mytheme_admin function. If you want you can replace add_theme_page with add_menu_page to create an external box :

At this step we still don’t have the theme options page, so we have to write mytheme_admin function which was called by add_theme_page, add this code to functions.php :

function mytheme_admin() {
global $themename, $shortname, $options;
if ( $_REQUEST['saved'] ) echo '<div id="message"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message"><p><strong>'.$themename.' settings reset.</strong></p></div>';
?>

Here we have some conditions : if the settings are saved WordPress will show ” Classic theme settings saved “. Likewise for reset.

Now paste the code above I will explain it after :

<div class="wrap">
<h2><?php echo $themename; ?> Settings</h2>

<form method="post">

<?php foreach ($options as $value) {
switch ( $value['type'] ) {

case "open":
?>
<table width="100%" border="0" style="background-color:#cdcdcd; padding:10px;">

<?php break;

case "close":
?>

</table><br />

<?php break;

case "title":
?>
<table width="100%" border="0" style="background-color:#868686; padding:5px 10px;"><tr>
<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
</tr>

<?php break;

case 'text':
?>

<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
</tr>

<tr>
<td><small><?php echo $value['desc']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

<?php
break;

case 'textarea':
?>

<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>

</tr>

<tr>
<td><small><?php echo $value['desc']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

<?php
break;

case 'select':
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
</tr>

<tr>
<td><small><?php echo $value['desc']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

<?php
break;

case "checkbox":
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><?php if(get_option($value['id'])){ $checked = "checked="checked""; }else{ $checked = "";} ?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
</td>
</tr>

<tr>
<td><small><?php echo $value['desc']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

<?php break;

}
}
?>

<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</div>

Explanation :

With this code we created our options page content : I used a php foreach loop, each option type is evaluated on a case-by-case basis. So if the type of the option is title do this, if it is a checkbox do that…

If there is an open type option we do nothing. If there is a close type options, we close our table. For each of the types text , select , checkbox and textarea , we display the corresponding input. At the end we added two buttons one to save the settings and the other to reset them.

Now our options page is ready, but we have to add this short code to make it work :

<?php
}
add_action('admin_menu', 'mytheme_add_admin');
?>

This short code tells WordPress to add the admin menu.

After all this, here the result you should end up with :

In this example I used simple styles included in functions.php to make our options page looks better but I will show you how to add a stylesheet to functions.php so you can add your styles rapidly.

How to add a stylesheet to functions.php :

First, you have to create a new folder on your theme folder, name it functions then create a new css file with a name of functions.css. After flling your css file add this code to functions.php after mytheme_add_admin function :

function mytheme_add_style() {
$file_dir=get_bloginfo('template_directory');
wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
}

That adds the functions.css file to the head. The location of the file is determined by the template directory.

Also, if you want you can use scripts to make your options page better by including a js file.To do this you have to change

wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");

To :

wp_enqueue_script("script", $file_dir."/functions/script.js", false, "1.0");

After adding your stylesheet or your script, you have to add this code underadd_action(‘admin_menu’, ‘mytheme_add_admin’); so they will be active :

add_action('admin_init', 'mytheme_add_init');

Making Use of the Options :

Now after creating our options, I will show you how to make use of them.First up, open up your header.php file, and add the following code:

<?php
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
?>

You must put the code above at the start of all the files which you add options to. Once youve done that you can begin using your options. For example : If you want to display the footer text you have to echo $ct_footer_text ( ct reffers to the shortname of the theme ) :

<?php
echo $ct_footer_text;
?>

For a checkbox you can check if the box is checked ( it will return true ) do this…

You can download the functions.php file here.

That’s it ! Thanks for reading this tutorial and I hope it was useful.

An Interview with Leland Fiegel of Theme Lab

Leland Fiegel is a 21 years old professional web developer from United States of America who specializes in development of WordPress themes. He is the guy behind Theme Lab which is one of the most famous websites for WordPress tutorials. Themes released at Theme Lab have been downloaded more than 400000 times . Today we are going to discuss WordPress, Theme Lab and his life in general. Join us if you are interested.

1WD: Many of us may be familiar with you because of your website: Theme Lab For those who are unfamiliar with you, can you tell us a bit about yourself and your life?

Leland: My name is Leland Fiegel. Im a web developer and blogger. Im a part-time student, a Lost fanatic, and an NBA fan. Ive been running Theme Lab for over two years now as my primary blog. I talk about WordPress, release WordPress themes, as well as post tutorials and coding tips.

1WD: How did you get started in web development?

Leland: Since I was around 10 years old, I was pretty fascinated with making websites. I discovered the View Source button on my old Internet Explorer browser and examined and played with code until I eventually taught myself HTML. I made a bunch of fun little sites (none online anymore, unfortunately) and just started getting in the business side of things about 5 years ago, when I started buying domain names, developing websites for them. My domain addiction carries on to this day, although Im getting better at not buying every good domain I see nowadays.

1WD:There is always a heated debate on WordPress GPL issue. Will you please share your personal views with us about this matter?

Leland:Ive said this before, but I dont believe there is any issue that gets the WordPress community more riled up than GPL-related debates. Arguments about commercial products and services, especially commercial themes, seem to always come back to the GPL in some way. I personally try to stay out of it as much as I can, as I believe there are much more productive things you could be doing than sitting around arguing about things that have been argued hundreds of times over already. Its like beating a dead horse. Some people might completely boycott non-GPL products, and thats up to them. Personally however, I dont mind promoting non-GPL products as long as I feel its a quality product.

1WD: Premium themes companies are growing like mushrooms. Do you think there is enough room for new WordPress premium theme companies in this over crowded niche?

Leland: It seems a new premium theme company pops up every day. Usually they are started by people noone has every really heard of before, they release a few mediocre themes, and then theyre never heard from again. These are what I call the fly by night sites. There are other new ones, however, who do a good job managing their credibility and reputation, put out a quality product, get good buzz flowing (usually by providing awesome support) and they probably end up doing quite well. Some established theme developers may say its too late to enter in the theme market. I personally dont believe that for one second, even though it may not be as easy to start up now as it was in the early days of commercial themes with all the noise. Everyone has to start somewhere, and theres always room for new, interesting, innovative, and quality new products.

Jungle Land – One of the most Popular Themes of ThemeLab

1WD:Each day, there are several WordPress theme releases in the community. What do you see in a “Quality” WordPress theme.

Leland:I see a quality WordPress theme as one with a clean design, with clean code running things behind the scenes. It doesnt necessarily need to have a boatload of theme options, a fancy magazine-style layout, or 50 social bookmarking icons built-in. It just needs to work and let you focus your content, without getting in the way too much. Themes that are slow loading, poorly coded, with subpar usability are themes that you should definitely stay away from, even if it may look flashy or cool on the front-end.

1WD:You are owner of Custom Theme, which offers custom theme development. Whats your day-to-day like?

Leland: Ill be honest in that I havent really been getting many complete custom theme job requests lately. Most of the work Ive been doing lately has been mostly coding related. Either coding mockups that people already have designed for them, or making matching WordPress themes so they can have a blog that blends in with the rest of their site. There is a big market for this as people recognize the value a blog could add to an already established website.

1WD: How do you concentrate while writing code, and what is your favorite code editor?

Leland : First step, CLOSE TWEET DECK. If I dont, I find myself constantly checking it to see the latest updates. And if I get a reply or a direct message and that little popup box appears, game over. Im Twitter addict too, in case you didnt notice. Closing Gmail also helps as well. My favorite code editor would have to be Notepad++. I dont need any fancy features, just something a little more useful than just straight Notepad.

1WD: Any code pet peeves?

Leland: Lets see, where do I start. When I see 0px instead of 0. When CSS shorthand isnt used properly (such as margin-top: 10px; margin-left: 10px; margin-right: 10px; margin-bottom: 10px; when you can say the same thing as margin: 10px;). When I see a bunch of <br/> tags to create space, when you should be using padding or margins in CSS. When I see a bunch of useless meta tags that noone cares about anymore loaded up in the header of a document, like Last Updated and Revisit After. Ill stop there, I think I have an idea for a future blog post.

1WD: What are your future plans?

Leland: Im planning on keeping up producing free content on Theme Lab, as well as posting paid content as well in a new section called the Underground. There will be paid themes, tutorials, as well as a private forum for members. Its something Ive wanted to do for a while because I feel like I have a lot of WordPress coding knowledge to share.

Thanks for your time, Leland.

Feel free to share your thoughts with us. Do you think we should continue such interviews or any suggestions you want to give us. We are open for ideas. :)

How to Create Your first WordPress Theme: Part 1

WordPress is the most popular and the best (in my opinion) blogging platform, created by Automattic. It’s really easy to use and it’s very powerful, giving you the opportunity to build any kind of site, from blogs to shopping carts and CMS’s. In this series of tutorials, we are going to create our first WordPress theme. For this tutorial you need to have a little more than basic knowledge about HTML and CSS. Let’s get started.You can Download source files and you can also Live preview the theme here. It’s a basic css layout so it will be easy for beginners to convert it into a working WordPress theme.

What we need

WAMP/XAMPP Server (orsimilar software)- Download

WordPress 2.9.2 (latest version, recommended) – Download

Getting started – creating the working environment

First thing first, you need to install WAMP Server. After installing WAMP, download and copy the WordPress files in the www directory from your WAMP folder. Start WAMP Server, click on the icon in the task bar, and a pop-up list show appear,then select phpMyAdmin.

Now, create a new database. Give it any name, but you need to keep it in mind as we need itat the WP installation. As for now, we are done with WAMP Server, just leave it running.

WordPress Installation

After copying all the files, you need to install WordPress. Enter on the address where you have put the WP files. The address wouldbe exactly, without any www or http, localhost or localhost/WordPress. After accessing the address, the installation may start.

Click “Create a Configuration File”. After this, you will see some listing of things you need to know. I’ll just tell you what you need:

  1. Database name: your given name of the database we’ve created earlier
  2. Database username: thisshould be “root”if you set it on your computer.
  3. Database password: there is no password set.
  4. Database host: localhost
  5. Table prefix: for now, leave it as it is.

Now, just fill in the fields with the required information, and go further! After filling up the fields, next give any name to your blog, and write your e-mail address.

Now, copy the auto generated password, and paste it in the password field at the site login. Now, because you cannot keep that weird password in mind, go the upper right corner of the site and click on “admin”. You should see a page where you have your account info. You can modify anything there, but for now we are setting a new and easier password.

Go to the bottom where it says “New password” and set your new password.

Good, now you have WP installed, but we have a lot more things to do.

1. Planning the theme layout

When I’m starting a new project on developing a WordPress theme, as everyone should do, I first build my HTML/CSS template. This is easier because you also learn how toconvert a simple HTML template into a fully functional WordPress theme. So i won’t go through building the template, considering you already know how to build your own. I’ll just use a simple layout from Free-CSS.com in this tutorial. Go here and download the #7 template.

2. Starting the conversion

When I’m making a theme, I’m always copying code snippets from a default WordPress theme (because i cannot remember all of them). I use the WordPress Classic theme, but you can also use a cheat sheet. The best one i’ve found is the one created by Ekinertac. After it opens in the PDF format, save it in your computer (you may need it when you do not have access to the internet).

All the contents from the sheetare the most used functions from WordPress, and the ones that you need to create a basic WP theme.

A thing that you have to notice is that WordPress is using PHP. Even if you aren’t a PHP master, or you have absolutely no idea what PHP is, you are still able to create a basic theme. When creating a theme, you need to know just tags and what they are doing, so do not worry about PHP.

2.1 Making the theme recognizable by WordPress

A very important part ofa WordPress themeis the CSS file. In the CSS file are written some lines that WordPress is using to g a theme. First, you need to rename the styles.css to style.css as WordPress is search for style not styles. Copy and paste these lines at the start of your CSS file:

/*
Theme Name: Free-CSS template WP version
Theme URI: <a href="http://free-css.com/">http://free-css.com</a>
Description: A very basic  WP theme based on a simple CSS layout from Free-CSS.com
Version: 1
Author:  >your name<
Author URI: >your site url<
Tags: free, css,  tutorial, simple, basic
*/

You can change everything that is located after the “:” dots. Save your CSS file as we won’t need it because we are just trying to give to the HTML template functionality.

2.2 Converting the HTML file

After you set up your CSS file, we need to go and change some things in the index.html file. First of all, clear all the sample text.
Save you file as index.php. We do not need the sample text anymore as we will introduce our own text from WordPress later.

Now, we need to make some declarations for the WP theme. We need to make the title dynamic and to set the stylesheet path. These lines will help you:

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<style type="text/css" media="screen">@import url( <?php bloginfo('stylesheet_url'); ?> );</style>

Now, we will start with the header of the design. For adding your blog’s name with a link to your homepage in the header, we will use this line of code:

<h1><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>

The first PHP tag is used for retrieving the blog’s homepage link and the second is for the blog’s name (the one you set in the installation).

Now we’re going further for the loop. The loop is a block of code that will repeat for each post from WordPress. We will use the loop to construct the article. I’ll cover more about the loop in the second part, where we will use it for other things too.

Now, all your code is wrapper by some loop specific tags. Here they are:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<!--Code to be repeated here-->

<?php endwhile; else: ?>
<?php endif; ?>

Next, we will start constructing the article structure. We will need a title, some info about the dat when the article was published and it’s author.

The following line makes the article title:

<p><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></p>

The first PHP tag is for the article’s link and the second is for the article title. These tags are kinda self-explanatory. We’re moving further for the meta data (date, author). Copy and paste the following code under the article title code:

<p>Published on <?php the_time('F d, y'); ?> by <?php the_author(); ?> in <?php the_category(','); ?></p>

First tag is for retrieving the date. The date tag have some parameters. These parameters are setting the date format (month, day, year). You can add characters like “-” or “.” or making something like “Month 02 Day 15 Year 1990″, it’s up to you! The second one, is for echoing the author of the post and the third, is for category or categories that the post is filed under.

Now, we will be placing the content tag. The content tag will output everything you write in a WordPress post:

<?php the_content(); ?>

The tag doesn’t need paragraphs because WordPress auto generates them for you. We’re finished with the loop. You can see the code pieces at the party:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <p><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></p>
 <p>Published on <?php the_time('m d Y'); ?> by <?php the_author(); ?></p>
 <p><?php the_content(); ?></p>
 <?php endwhile; else: ?>
 <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
 <?php endif; ?>

Next, we will be going to code the sidebar.

We will start with the navigation. As you see in the CSS layout, the navigation is located in the sidebar. It doesn’t matter because the technique is the same. For creating a basic navigation you need these lines of code, which will placed between the <strong>ul </strong>tags:

<li><a href="<?php bloginfo('url'); ?>">Home</a></li>
<?php wp_list_pages('title_li='); ?>

You already know what the first PHP tag does. The second one, is listing the pages that WordPress generates. The parameter is for list title. Try removing it and see what’s happening.

This is all you need to do for getting a nice working navigation menu. Now, we will create the categories list. All the blogs have categories and we don’t want our theme to lack categories. We will just add this code between the div #extra tags:

<p><strong>Categories</strong></p>
<ul>
 <?php wp_list_categories('title_li='); ?>
</ul>

There is another listing tag but this one is listing the blog’s categories. I’ll cover more things relating the sidebar in part 2, where i will teach you how to make a theme widget-ready. That means you will introduce new blocks inside of WordPress, without coding anything.

But what about the footer? Shouldn’t it have some text in it? Well, we will write the copyright:

<p>Copyright &copy; 2010 <a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>. All rights reserved.</p>

As you see, we have introduced some tags, just like in the header, to output the blog’s title.

The theme is functional, but we will need to make some page templates for single post (where the comments will appear) and the page (where you could write some info about your blog). If you use the same code for the header footer and sidebar, your template would get messy. Let’s say that you want to add one more thing to your sidebar. You will have to modify 3 times for each page template. Well, for avoiding this, we will chop the markup.

For each section of the index.php file we will have a separate file. So we will have header.php, footer.php and sidebar.php. Now, we will be starting to chop!

Copy and then replace the following lines:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<style type="text/css" media="screen">
@import url( <?php bloginfo('stylesheet_url'); ?> );
</style>
</head>
<body>
<div id="container">
<div id="header"><h1><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>
</h1></div>

With the following line:

<?php get_header(); ?>

Your copied code needs to be placed in the header.php file. The same thing we will do with the footer and sidebar

Copy the following:

<div id="navigation">
<p><strong>Navigation Here</strong></p>
<ul>
 <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
</div>
<div id="extra">
<p><strong>Categories</strong></p>
<ul>
 <?php wp_list_categories('title_li='); ?>
</ul>
</div>

Paste them to sidebar.php then in the index.php file replace it with:

<?php get_sidebar(); ?>

Now, do the same thing with the footer. Copy the footer div and it’s contents, paste it in footer.php file, and then remove it in index.php with:

<?php get_footer(); ?>

You should have something like this:

<?php get_header(); ?>
 <div id="wrapper">
 <div id="content">
 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <p><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></p>
 <p>Published on <?php the_time('m d Y'); ?> by <?php the_author(); ?></p>
 <p><?php the_content(); ?></p>
 <?php endwhile; else: ?>
 <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
 <?php endif; ?>
 </div>
 </div>
 <?php get_sidebar(); ?>
 <?php get_footer(); ?>
</div>
</body>
</html>

Now you’re done with chopping the markup. We are going to create the page templates. We will create firstly the single template. Just save your index.php file as single.php. We won’t modify anything in this page yet. We will do it in part 2 where I will learn you how to create a comment form and how to list comments and other things like custom fields.

Now, for the static page, page template, delete the line where you have placed the meta data (the line with date, author and category tags). Then save the file as page.php. Being a page, we won’t need any info about the creation date or the author. We won’t even use comments on page because there is no point in it.

The last move we need to do is to print screen our template and save it in a canvas of 300 x 225 px and save it as screenshot.png in the root directory of your theme. This will be used in WordPress theme menu.

Well, we’re done with the first part. Go ahead and test your theme. If there is something you want to ask, do it via comments. Don’t forget that you can download the source files too.

To be continued

There are a lot of things to cover about WordPress. Making a theme isn’t so difficult, you just need to be patient. There are a lot of things that are needed to make a fully functional WordPress theme. That’s why, this tutorial will have a Part 2. Maybe there will be more parts, but i will let you know what I will be covering in the next part:

  • Widgetizing the sidebar
  • Using the single page template: comments, custom fields, author details
  • Using custom fields for showing an image for each article
  • Making a nice and working search form

Stay Tuned.