By default, WordPress displays your php files by whatever the file name is. That means if you name your file wordpress.php, that is how it will show in your WordPress editor. When working with page templates, or if you just want to keep your files a little more organized, you’ll probably want to give your templates names.

Here is all you need to do. Paste the following code at the top of the file:

<?php
/*
Template Name: WordPress PHP
*/
?>

Now change WordPress PHP to be the name you want to use. Easy enough, right?  Tomorrow I’ll be posting a little more about page templates!

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

One of my favorite parts about using WordPress for my blogs is getting to work with PHP code, which I find to be much easier to write/hack.   For those that are shy around code, it really isn’t that difficult to get ahold of the basics of PHP, so WordPress is the right place for you. 

One great area to start is learning how the WordPress loop works.  This is a basic function of blogging used to display the most recent X number of posts on your blog’s homepage (for traditional blogs).   Rather than go into to much detail here, I’d like to point you towards a new post by Themelab which is designed to be the Utlimate Guide to the WordPress loop

This post definitely lives up to its name and goes beyond just showing you how to do something.  It actually explains how and why it works, and includes screenshots with many of the examples.   If you have any interest in learning about the WordPress loop you may want to read through this post and/or bookmark it for future reference. 

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

Depending on how your WordPress blog is set up, you may have an interest in displaying your WordPress tags for your readers to dig through in a nice looking cloud format. This is something that is very nice for readers to see, as long as you are responsible with your tagging and don’t use an overwhelming number of tags.

In order to display tags on your WordPress blog, you’ll just want to add this little code snippet whenever you want the tag cloud to display (usually in the sidebar or footer somewhere depending on your blogs layout).

Here is the code you’ll need:

<?php wp_tag_cloud(''); ?>

WordPress also allows you to customize your cloud to display the way you want it to. Most people like to emphasize the most used tags by making their font much larger. You can determine the size using the following code:

<?php wp_tag_cloud('smallest=8&largest=36&'); ?>

In this example, the tags will be displayed in alphabetical order with the least used tags being 8px and the most used tags will be 36px. You can of course adjust this to meet your needs.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

So, you have an established WordPress blog, but you’ve seen the pro bloggers doing it and now you want to turn that blog into a Content Management System (CMS)? Many people probably weren’t aware of this trick (including many web developers), but one neat feature added with WordPress 2.1 was the ability to have a different home and blog page without needing to install WordPress on a completely new directory.

In order to accomplish this, you first need to make sure that the page that you want to be your blog’s homepage is named home.php. This will be the page displayed at the root of your domain.

Next, you’ll want to create a new file named blog.php and place the following code within the file:

<?php
/*
Template Name: Blog
*/
// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);
// make posts print only the first part with a link to rest of the post.
global $more;
$more = 0;
//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
?>

That is all you need for code in that file. Upload it to your theme. This code creates a loop of your index.php file in your theme (commonly used as the single post page) and displays it as a typical blog homepage. Because this page will pull from your index.php file, going forward, any changes you make to your index.php file will update on this page as well.

Now, go into your dashboard and create a new page called Blog. Then select the Blog file you just created in the Page Template drop-down menu in the right sidebar.

Once that is done, the last thing you need to do is go over to your permalink structure page (under Manage) and add /blog/ to your custom permalink structure. This means if you are using an optimal permalink structure, you would want to use a custom structure of /blog/%postname%/. If you are doing this to an established blog, you can easily use the Permalink Redirect plugin to redirect your old permalink structure to the new one.

To see this in action, you can check out my personal blog, Kyle Eslick dot com. If you have any questions, feel free to post them below and I’ll do my best to answer them.

Edit: This was written for WordPress 2.1 through WordPress 2.3.3.   It appears that a slight adjustment has been made for WordPress 2.5+.   Readers have confirmed that you can find the information you for a WordPress 2.5+ install in this post.   If you are using WordPress 2.5 or newer, please keep this in mind if you try this.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

When you think of having two stylesheets for a website or blog, you typically think of an alternate stylesheet specifically for a web browser, such as an Internet Explorer stylesheet.

One thing we haven’t covered yet is how to add a second stylesheet that is only used for certain pages. In order to do this, you’ll want to open up your header.php file and locate your existing stylesheet. The stylesheet code should look something like this:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

Now, we need to make an adjustment so that it will only show the code in a certain situation. For example, if you want a certain category to use a different stylesheet, you’d use the following code:

<?php if ( is_category('1') ) {
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/cat-1.css"
type="text/css" media="screen" />;
<?php } else { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"
type="text/css" media="screen" />
<?php } ?>

In this example, we are assigning the cat-1.css to be used for category 1. Every other page will use the normal stylesheet.

You can plugin in alternate information as needed.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

As we continue to gear up for WordPress 2.5, have you gotten your theme ready for Gravatars? In the past it required plugins, but now WordPress 2.5 has built-in Gravatar support. This means going forward, themes can easily be released with Gravatars built-in to the theme because no plugin will be required.

So, you’ve got WordPress 2.5 installed and you’re ready to assign Gravatars to your comments? All you need to do is a quick code hack to the comments loop where you want the Gravatar to show up:

<?php if(function_exists(’get_avatar’)){ echo get_avatar($comment, ‘50’);} ?>

I encourage everyone to support WordPress by displaying Gravatars on their blogs once you’ve upgraded to WordPress 2.5.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |