Custom Category, Page and Post Templates for WordPress

Quick overview of custom templates for WordPress Categories, Pages and Posts. You may already be familiar with Category and Page templates but custom Posts templates are just as easy.

DISCLAIMER: Before making any edits to original files make sure to have backups in case something goes terribly wrong…not that it should but you can never be too safe!

WordPress Category Templates
WordPress Category templates are very easy to use, view the WordPress Codex – Category Templates and you will see that hierarchy for a category templates is:

  • 1. category-6.php
  • 2. category.php
  • 3. archive.php
  • 4. index.php

This basically just means that WordPress will first look for a template labeled category-6, if there is none, it will then look for category.php and so forth all the way down to index.php.

To create a custom category template, just copy your category.php and resave it as category+”your category ID number.” If you do not have a category.php, you can copy your archive.php or index.php but just remember that your custom template will look like the template you copied until you make your edits. So if you have a category.php, archive.php and index.php you will want to copy your category.php and work from there.

You can find your category ID number by logging into your WordPress backend…go to your categories section and hover over or copy any category names and you will see your category ID. Upload category-”ID#”.php to your theme directory and the specified category can now be freely styled to look differently than your other categories.

WordPress Page Templates
WordPress Page Templates may be easier than Category Templates. WordPress looks for templates in the following order:

  • 1. The Page’s selected “Page Template”
  • 2. page.php
  • 3. index.php

Let’s pretend we want to create a specific template for an “About Us” page. Most themes will have a page.php so once again, you can copy your page.php and resave it, let’s call it about.php.

Once resaved, our page template must start with the following 5 lines of code so add the following to the very top:

<?php
/*
Template Name: About
*/
?>

The above sets a name for your page template, so you can enter just about anything in the Template Name: “Your Choice” For the ease of consistency I would label the template name something similar to what I am saving the file, so this about.php will have a Template name of About. Now that you have your Page Template named along with some copied format from your original page.php you can edit this about.php to your hearts desire. Any edits made to about.php will only affect those pages using this template. Upload your new about.php to your theme directory and we are all set.

To use a Custom Page template just create or edit any page. You should see a dropdown box labeled Page Template, if all is in order you should see your template name as an option in the dropdown.

WordPress Post Templates
WordPress Post Templates are great because they allow you to make posts in different categories different from each other.

For example let’s say you had 2 categories named Apples and Oranges. You styled each category differently using Custom Category Templates but also wanted posts that appeared in Oranges to have a different look than posts appearing in Apples.

Custom Category Templates do not pass any styling to the posts within, posts take their styling from either single.php or index.php as per the WordPress Template Hierarchy.

Most themes will have a single.php, so yes once again duplicate your single.php…twice. We only need two Post Templates in this example since we want one Post Template for Oranges and just use our original Post Template for posts appearing in the Category Apples and the rest of our posts in our blog.

Let’s name one of our copies of single.php to singleOriginal.php, this is a direct duplicate of our original file unedited.

For our second copy of single.php that will be used as a Custom Post Template for the posts in Oranges, let’s save this file as singleOranges.php. This file will be the edited single.php that will have whatever custom edits you want for all Posts in the category Oranges. Make your edits to this file and you will also need to retrieve the category ID for the category Oranges, let’s pretend it has an ID of 10.

Recap
Before we move ahead, let’s make sure we have everything in order, we should have 3 files and 1 Category ID number.

The 3 files consist of a singleOrignial.php which is a direct duplicate of our original single.php. We should also have a singleOranges.php which has our edits for our custom look for all posts in the category Oranges(ID #10). And finally we should still have our original single.php unedited in it’s original format.

Now let’s edit single.php since WordPress first goes to single.php for all Post Templates. Edit your single.php with the following:

    <?php
    $post = $wp_query->post;
    if ( in_category('10') ) {include(TEMPLATEPATH . '/singleOranges.php');}
    else {include(TEMPLATEPATH . '/singleOriginal.php');
    }
    ?>

That’s it! Basically the above checks the posts to see if it’s category 10, if so use the template singleOranges.php, else use singleOriginal.php. What if you wanted a Custom Post Template for Oranges, Apples and Grapes but still wanted a single.php for everything else?

    <?php
    $post = $wp_query->post;
    if ( in_category('10') ) {include(TEMPLATEPATH . '/singleOranges.php');}
    elseif ( in_category('11') ) {include(TEMPLATEPATH . '/singleApples.php');}
    elseif ( in_category('12') ) {include(TEMPLATEPATH . '/singleGrapes.php');}
    else {include(TEMPLATEPATH . '/singleOriginal.php');
    }
    ?>

A very easy way to customize posts in any category. Go ahead and get creative with customizing then come back and leave a comment to show it off, would love to see what some people do!

I Love My iPhone Apps

For anyone who has an iPhone you probably already know that there are plenty of iPhone apps at the iTunes App Store. For those new to owning a iPhone, some apps come at a cost while there are many others free to download.

I have close to 50 apps loaded onto my phone, but in reality there are only a handful that I use on a daily basis.

As the App Store is about to hit 1 billion downloads, here are “5 Must Have Free Apps” that I find to be great.

  • TwitterFon – Yes Twitter is just about everywhere nowadays. From P. Diddy, to your local News Channel it seems that everyone has a Twitter account. The great thing about TwitterFon is that you have a menu bar on your screen which lets you sort through your Friends, Replies, Messages, Favorites and an option to Search. View profiles, see timelines and be able to retweet makes this my go to Twitter app.
  • Google – Even if you don’t have a Google Account to make use of the Gmail, Calendar, Docs etc. features, just installing this app for the the Google Search feature is worth it. If you search using the google search bar using the iPhones built in Safari browser you will see the same results as you would on your computer If you use the Google App search you will get results tailored to your location. Not to mention search by voice is pretty cool.
  • Fandango – Need to check what’s playing at your local theatre? Pop in your Zip Code and you are all set. Never tried to buy tickets through it but it is an option if your theatre supports it.
  • Free Wi-Fi Locator – Using your current location this little app returns the nearest locations that offer Free Wi-Fi. This is not to be confused with other apps such as WiFinder which just searches for the nearest Wi-Fi locations.
  • Pandora – Streaming music to your iPhone based on your choices. Listen to a song or two and Pandora will start to recommend music based on what you just heard. Create specific stations for different genres and enjoy free streamed music.

The above are only a handful of great apps so also check out: Skype, Mint.com, Facebook, AIM, Brightkite, Urbanspoon, Yelp and iTalk, you won’t be disappointed.

Have an app that you love? Please leave a comment and let me know, free or paid I love downloading and testing out new apps!

Embed Ads Into Your Twitter Tweets With Adjix

Uh, oh.

Those were the words that came out of my mouth this morning when I checked my email on my iPhone. For those registered to Adjix you may have received an email from the company announcing their new advertising format in which Twitter users will be able to embed an ad at the end of their Twitter Tweets in order to monetize off of their number of followers.

Adjix’s current ad program is based on link shrinking and including a text link on the top portion of the site as long as you are logged into your account on Adjix when shortening your link.

What’s actually useful about Adjix is that they offer several features such as the ability to track the number of clicks your unique shortened link receives. Not only are stats recorded for links with ads but there is an option to shrink a link without an ad, and yes you will still be able to track clicks for that URL.

Do people actually use the service for click tracking and not to serve ads?
Yes. More importantly one of the Twitter elite, @guykawasaki uses the Adjix service very frequently(to shrink and record stats) and if you visit his Twitter stream you will see that most, if not all of his links begin with http://adjix.com.

Adjix has a video demo of their new feature as well as details on their blog outlining Advertiser Info, Twitter User Info and how to install their bookmarklet in order to start embedding ads into your Tweets.

Luckily for me the only person I follow that uses Adjix is @guykawasaki, but the thought of monetizing on Tweets to a large list of followers may cause several to sign up and start using Adjix’s new ad embed. If so, we very well may see more Tweets as the mock put out by Adjix.

Running PHP 5 for WordPress with 1&1 Hosting

If you are on a shared hosting plan with 1&1 it’s relatively easy to create a new MySQL Database for your WordPress installation.

Creating Your New Database
Just sign into your account and navigate to Web Space & Access and then to MySQL Administration. Click on “New Database” and you will be prompted to name your new database along with the option of choosing between MySQL 4.0 and MySQL 5.0 for your new database. WordPress Requirements state that WordPress need PHP 4.3 or higher to function properly although a few plugins require that you use PHP 5 to function. Choose MySQL 5 and your database will begin setup.

Since we created a new database and chose the option of MySQL 5 your database is using PHP 5 right? Unfortunately that’s not the case.

Checking Your PHP Version by Creating a phpinfo.php File
1&1 will have your new database running PHP 4.4.9. Easiest way to check what version of PHP you are running is to create a phpinfo.php file and insert the following.

<?php
phpinfo();
?>

Upload this file to your directory and open phpinfo.php in your web browser.

The information at the top of this window will display the version of PHP that you are running.

Forcing 1&1 to Use PHP 5
It only takes 2 lines added to your .htaccess to force 1&1 to use a version of PHP 5. Add the following to the first 2 lines in your .htaccess file.

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

Once you make the edits to your .htaccess upload it to your directory and once again open phpinfo.php in your web browser. You should now be able to see that your database is using PHP 5

Quick Tip from JG in the comments:
I found once I updated the .htaccess file, then all my links would break from the homepage. What I did was go to the permalinks page under settings and click ’save changes’. You don’t have to actually change anything.

Then when I found pages that wouldn’t load, simply refreshing the page made them work again.

Page 4 of 8« First...3456...Last »

Contact

Questions, inquiries or just feel like getting in touch, feel free to do so: