How To Display Different Ads In Separate Categories
Sunday, December 27, 2009, 2:10 AM | 1 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.
Throw us a like at Facebook.com/doable.finance
One Response to “How To Display Different Ads In Separate Categories”
By Go Here on May 14, 2013, 5:17 am | Reply
It’s a shame you don’t have a donate button! I’d certainly donate to this excellent blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will share this site with my Facebook group.
Talk soon!