• Technosailor.com
  • Desk of the Editor
  • Entrepreneurship
  • Web Marketing
  • Tech Policy
  • Contenido EspaƱol
Technosailor
  • Blog
  • Authors
  • Twitter Pitch Me!
  • Disclosures
  • Advertise on Technosailor.com
Mar
31
2007

WordPress FAQ: How Do I Use Category Themes?

Posted by: Aaron Brazell
Woodlawn, MD, USA

Is it possible to have different layouts, theme or links depending on the category the user has clicked?

This question comes from Milo Riano. Milo wants to be able to have what I call a “flexi-site”. A Flexi-site is a site that is flexible in terms of display options or layouts. This could really be an extension of the question about multiple blogs as well.

Template Files

The key here is in template file hierarchy. WordPress looks in the theme directory to find the following files, and in this order:

  • category-X.php
  • category.php
  • archive.php
  • index.php

So if you have a blog that you assign a category of “Linkblog” to, and you want the linkblog to be displayed in a different format that the rest of the blog, you could simply find the ID number of the category (We’ll call it 23 for the sake of argument), and you could create a special template file with the unique layout you wish to use, and call the file category-23.php. Now everytime the category page is loaded, the template file category-23.php will be used.

Custom CSS

You can take this approach a step farther through customized CSS stylesheets. As most templates use the inbuilt function <php get_header() ?> to summon the use of the common header.php file from the theme, it is also possible to create custom headers and include those directly.

However, the better solution to this, providing you don’t have a vast number of categories that you want to display different CSS files for, is to simply use the WordPress template tag is_category() to figure out whether to display an alternate stylesheet.
<php if( is_category( 23 ) ) { ?> <link rel="stylesheet" href="http://example.com/wp-content/theme/cat23.css" type="text/css" media="screen" /> <php } else { ?> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <php } ?>

You can get real creative with this instead choosing to use is_category() to determine if extra CSS can be added after the main CSS thus overriding styles. There are quite a few options and you are limited only by your creativity.

If you have questions for this ongoing WordPress FAQ series, shoot me an email and let me know. By doing so, you’ll get a free link to your site.

Table of contents for WordPress FAQ

  1. WordPress FAQ: How Do I combine Blogs?
  2. WordPress FAQ: What’s up with the Amazon Plugin with WP 2.1.x?
  3. WordPress FAQ: How Do I Use Category Themes?
  4. WordPress FAQ: Where did my Preview Link Go?
  5. WordPress FAQ: How Do I Use Child Pages More Effectively?
  6. WordPress FAQ: How Do I Fix the Blogroll Category Issue in WordPress 2.1
  7. WordPress FAQ: How do I Move my blog to a new host?
  8. WordPress FAQ: User Roles Confusion
  9. WordPress FAQ: What is the best way to upgrade a WordPress 1.5 blog to WordPress 2.1?
  10. WordPress FAQ: Democracy Poll Feature
  11. WordPress FAQ: Benefits of Tagging
  12. WordPress FAQ: What’s the Best Way to Backup my Blog?
  13. WordPress FAQ: How Do I Integrate WordPress Into a Non-Blog Site?
  14. WordPress FAQ: Troubleshooting a WordPress Install
Previous in series Next in series
  • Add to Mixx!
  • Stumble it!
About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He served as Director of Technology at b5media from 2005-2008 and is currently an independent consultant.
Tagged: WordPress FAQ at 12:29 am -
discussion by DISQUS
Add New Comment
Go to Forum —  Track Comments —  Comments RSS
  • Recent Posts

    • When is a Vote not a Vote?
    • The Hidden Human Cost of Government Going Green
    • Understanding our Future by Understanding our Past
    • Ford EcoBoost Cuts CO2 Emissions by 15%, Improves Gas Mileage
    • 5 Things Small Businesses Can Do To “Be Green”
  • Recent Comments

    Powered by Disqus
  • Tags

    Aaron Brazell Advertising Apple b5media Blogging book conferences Design entrepreneurship Facebook Finance and Funding Google guest_blogging holidays humor hurricanes_and_natural_disasters interesting job Links Marketing Music nfl Op-Ed Perfect Pitch personal politics pr Predictions productivity Programming Security Social Issues Social Media Social Networking social_issues Sports Tech Industry Technology Technosailor Travel twitter unix Venture Files WordPress you_can_blog

  • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy

    Twitter Pitch!

    <p>Twitter pitching is a form of pitch that requires succint "what does this mean for me" kind of pitching. It is the ultimate efficiency of words. You have 140 characters or less to tell me why your pitch matters to me or my readers. Please include a means of contacting you. This is included in your 140 characters. If you send successive pitches, you will likely be ignored, unless it's obvious that the first pitch was a case of "accidental send", etc.</p> <p>This form of pitching does not mean I'm being a diva. It means that my time is valuable, and you want a piece of it. It's good practice for you, and delivers your pitch in a format I want. Win-win.</p>


    (X) Close

    Twitter Pitch Me!