The base for this code modification is Mystique WordPress Theme created by Digital Nature version 2.4.2.
One of the first things I did when I started mucking around with the theme was to change the header so that a different tagline displayed depending on what category you were in. (A holdover from the days when I had six different blogs.)
Since I’m not using the category description, the following shows how to manually set the various taglines AND how to use category_description if you’d rather.
Ready to rumble? Then pop open Appearance -> Editor and read on…
In header.php, right after:
I put in the following bit of PHP in order to grab the category information:
< ? php $category = get_the_category();
If you want to use the category_description for the tagline instead of putting in a new phrase add this on the next line:
$tagline = $category[0]->cat_description;
If you want to use a new phrase based on the categoty name add this instead:
$toprank = $category[0]->cat_name;
You could use the cat_ID (category ID number) or the category_nicename (category slug) instead of the cat_name (category name), I just liked using the name.
Then, right below that you're going to add in the if-elseif-else code below. There are two version, one for the category description and one for a hardcoded phrase.
If you are using the category_description then you'll want to use this code:
if (is_category()) {
// If the page is displaying a category then use the category description as the tagline
echo $tagline;
} else {
// Otherwise use the blog's description
echo get_bloginfo('description');
} ?>
If you are putting in the phrases manually (like me), you’ll want to use this code. Just replace the category names with your own information:
if (is_category()) {
// If the page is displaying a category then try to match the category name
if ($toprank == '1 - Unquiet Bones') {
echo " Putting Dreams to Paper";
} elseif ($toprank == '2 - Custom-Models.com') {
echo " Custom Model Horses in Every Hue!";
} elseif ($toprank == '3 - Perish Twice') {
echo " Of Dual-boxing and Death";
} elseif ($toprank == '4 - Everyday Dragons') {
echo " Remembering How to Fly";
} elseif ($toprank =='5 - View From the Molehill') {
echo " Impersonating a Grownup with the Best of Them!";
} elseif ($toprank =='6 - Martha.net') {
echo " There's no place like 127.0.0.1";
} else {
//This was just to check and see if posts were missing categories
echo " Note to Self : Fix top level category for this post";
}
} else {
//If the page is not a category, they use the default catchphrase
echo get_bloginfo('description');
} ?>
With this in place, a new catch-phrase was displayed as folks navigated around on the blog.
Not really rocket science, but it was the first step in learning how to fiddle with the PHP to make things do what I want.
Problems with the code? Just leave me a comment and I’ll try to help you sort things out! ๐
Leave a Reply