Unlimited<br /> Autoresponders by AWeber

Posts Tagged ‘Cascading Style Sheets’

Adding The Category Description To The Category Page

Firstly, why would you want to do this? It can be changed as often as you like which can be seen as new content and it can give important information to your readers as to what they can find in the category and should encourage them to dig deaper than the front page.

1) You need to have a separate page for categories in your theme (category.php)
If you do not have a category.php make a copy of your index.php and rename it category.php.

2) add <?php echo category_description(); ?> to category.php where you want the category description to show (This should be outside the ‘Loop’, if you do not know what this means start by putting it at the top of the page, save, upload and refresh to see what you have and if it is not in the right place you can move it down adn do the same.

BONUS - If you only want to have the description on the first page of the category you need to add the php code to show the category into it’s own ‘Loop’ like this;

<?php if ( $paged < 2 ) { ?>
<p><?php echo category_description(); ?></p>
<?php } else { ?>
<p>YOU CAN CHANGE THIS LINE TO WHATEVER YOU LIKE AND THIS WILL ONLY SHOW ON P.2 OR HIGHER</p>
<?php } ?>

Don’t forget that you will probably need to amend your css stylesheet to incorporate a style for your category description.

BONUS 2 - The php code to display the category title is <?php single_cat_title(); ?>

You can see how it works by clicking on one of the categories on the left hand navigation menu and you will see the category title and description at the top of page 1 only. (if you are looking at it today I have not yet amended the css stylesheet)