Category page in wordpressI recently updated my category pages and added some text over each of them. I thought this would be helpful for the new visitors to understand what I’ll be writing under that category.

You can add any text or images in your category archive page by editing the category.php file. Follow the simple instructions below to add the text or images:

Steps to edit your category.php template:

1. Go to Appearance>Editor from your dashboard and open category.php file from there.

2. Now add the following code outside the loop:

<?php if (is_category('Category 1')) : ?>
<p>Enter your text or image here for category 1</p>
<?php elseif (is_category('Category 2')) : ?>
<p>Enter your text or image here for category 2</p>
<?php else : ?>
<p>Else display this text of image for all other remaining categories.</p>
<?php endif; ?>

Now what this does it first checks if we are looking at Category 1, if we are then it displays the respective text or image. Otherwise checks if we are looking at Category 2, if we are then it displays the respective text or image. If this condition is also false it shows the default text or image.

3. Save the file and you’re done. Refresh your category pages to see the change. Now you can add as many categories you want by simply adding elseif (is_category(‘Category X’)) under category 2 and so on.

Adding background to the text

Now you may have see that I have blue background behind the text on category pages. If you also want to add the background follow the following instructions:

1. You’ll have to first make a new class or ID in you style.css file (Appearance>Editor). If you don’t know what this means just copy paste the following code at the end of your style.css file and save it.

.cat-text {
background: #e7f3ff;
border: 4px solid #bedeff;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
padding: 20px 12px 12px 20px;
margin-right: 53px;
}

2. Now go back to your category.php page and add the following code above the loop instead of the code given above. What I have done here is I created a new division for the category text and added some styling to it. Here is the code:

<div class='cat-text'>
<?php if (is_category('Category 1')) : ?>
<p>Enter your text or image here for category 1</p>
<?php elseif (is_category('Category 2')) : ?>
<p>Enter your text or image here for category 2</p>
<?php else : ?>
<p>Else display this text of image for all other remaining categories.</p>
<?php endif; ?>
</div>

3. Save the file and reload the category pages to see the change.

I hope this helps. If you still have any doubts post a comment below and I’ll try to help.

Share this post...Share on Facebook1Tweet about this on TwitterShare on Google+0Pin on Pinterest0Share on StumbleUpon1