Monthly Archives: February 2008

Alternate Background Color of Blog Posts

As my tag pages grow I have been contemplating how I wanted to handle their appearance. The goal is to have as many post excerpts as possible on each tag page while creating a page that is easy to read. I decided to try something a little different that I have not seen on too many blogs, actually, I am not sure I have seen it at all except on some comments, which is alternating the background color of each post.

So, how hard would this be?

It took about an hour to get it the way I wanted it. I am alternating the background color and the Adsense ads on each tag page. A good example is the Google Tag Page since it has a lot of posts.

Rotate Background

Here is a summary of how I did this:

Create a loop counter. Right before the Loop begins set a variable to zero.

if (have_posts()) : ?>

At this point I would want the Background Color to change, insert code to test for an even number post, and if this is true, add an inline CSS style for the background that would override the stylesheet.

<?php if ($odd = $x%2){?>
<div style=”background-color:#404040;padding:10px 0px 10px 10px;”>
<?php }?>

Then, where the background color should return to the original state, run the same test for the even numbered post and close the div tag set by the Inline Style.

<?php if( $odd = $x%2 ){?>
<?php }?>

The final step is to add 1 to the counter for each post, which is done at the end of the loop.

endwhile; ?>

Not sure if anyone else likes this style, but it sure seems to make the excerpts easier to read for me. Please let me know what you think ?

Google Grandcentral

Google GrandCentral is now in Beta and allowing non invite registrations. There are several features of Google GrandCentral that make it stand out. You can now have a phone number that allows people to call you without them knowing your actual phone number, lets see, did that make sense?

Let’s try it this way, One Number, Multiple phones!

For Bloggers it is a great tool to allow your readers to contact you without posting your home, office or cell phone number. You can add a web button, like the one in my right sidebar that allows a reader to enter their name and phone number, then the system connects the call and it rings back to the reader. You can also set the system to take all calls to voice mail and from there you have several more options.

Once a voice mail is received an email is sent to you immediately. You can listen to the message, download it and even post it to your blog. Here is an example thanks to Garry Conn !

Here is the link to the free invites, so make sure to check it out. Even if you are not posting it on your blog it can be a great tool to help manage your phones.As usual, it just took a little patience to see what Google would do once they acquired GrandCentral last summer, and it looks like they have a great start with the first release of Google GrandCentral.Link : Blog Release at Blogger Buzz

WordPress Template Hierarchy

The WordPress Template Hierarchy is a critical part of truly understanding how your WordPress blog works.

Have you ever wondered why some WordPress themes have certain files while others do not?

A WordPress theme requires only two files as I have discussed before, the index.php and style.css. If you took a basic WordPress Theme and deleted all the files except those two in the theme folder, it would still work. However, the pages would basically look the same.

Now the question is, where do these other files come from? And how does WordPress know which ones to look for? This is actually a very simple process. WordPress uses a page hierarchy to choose which files to use for each type of page.

As an example if there is a single.php file, WordPress will use that for the individual (single) post, if that file does not exist, it will use the Index.php file.

There are 10 basic WordPress Theme pages, these are:

  • 404 (Not Found) page
  • Attachment page
  • Author page
  • Category page
  • Date page
  • Search Result page
  • Single Post page
  • Tag page
  • The Main (Index) page
  • WordPress Page

This gives us the ability to customize each type of page. This WordPress Codex page explains the Hierarchy.

Let’s look at the Tag.php page as a more specific example.

The Tag page hierarchy goes like this.

  • The Tag Template with a matching slug. If the tag’s slug were sometag, WordPress would look for tag-sometag.php
  • tag.php
  • archive.php
  • index.php

So if your WordPress theme does not have a Tag.php page you can easily copy the archive.php page to create a custom tag page, if you do not have a archive page, you could copy the index page to start your tag page.

To help you I have created a simple text file that lists the WordPress heirarchy that you can download here.

So with just a little thought and practice it is very easy to create very unique pages for your WordPress Theme.