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.



Related Posts On Doable Finance dot Com

  1. How to display excerpt and complete content in WordPress



Leave Your Comments!

Your email address will not be published, period.


*

Please follow Doable Finance dot Com Comment Rules.


Click on the left to read more similar articles.




 

 

 

 

Top Of Blogs Blog Top Sites Blog Flare Blog Top List Blog Top List
Top Blogging Top Blog Area On Top List My New Blog My Zimbio Blog Log Blogs Avenue