How to display different ads in separate categories
Sun Dec 27, 2009, 2:10 am | Leave Comment
If you have more than one category like I do on this blog and you want to display ads according to the topic of the category, then you need to add some php code to your theme files. I use WordPress platform so this is targeted towards that.
I created a file and named it ads-category.php and filled it with the following:
<?php if (in_category(‘Blogging’)): ?>
<?php include (TEMPLATEPATH . ‘/ads-blogging.php’); ?>
<?php elseif (in_category(‘Careers’)): ?>
<?php include (TEMPLATEPATH . ‘/ads-careers.php’); ?>
<?php elseif (in_category(‘Credit’)): ?>
<?php include (TEMPLATEPATH . ‘/ads-credit.php’); ?>
<?php elseif (in_category(‘Technology’)): ?>
<?php include (TEMPLATEPATH . ‘/ads-technology.php’); ?>
<?php endif ?>
You can repeat it for as many categories as you want. I then used this file in a condition as
<?php if (is_category()): ?>
<?php include (TEMPLATEPATH . ‘/ads-category.php’); ?>
<?php endif ?>
and used it wherever I wanted the ads in a category to appear.
Notice that the specific category is conditioned as in_category() and is_category() is used when the user has clicked on any category.
Then I filled each file of a category such as ads-blogging.php or ads-credit.php with targeted ads specific to that category.






