Serve different banner ads in wordpress based on tags/keywords?

matt3

Member
Jun 15, 2009
660
9
18
Does anyone know if there is plugin that does this?

If not, what would be the best way to go about serving content keyword based banners for different products?

Thanks
 


Well if its just for one theme then you could iterate over the results of get_the_tags Function Reference/get the tags WordPress Codex

Code:
$banners=Array();
$banners['handbag']='<a href="http://handbags.faux">Buy Hand Bags</a>';
$banners['high.heels']='<a href="http://myclothingshop.faux">Clothing Rocks</a>';
// ....

if($postags=get_the_tags()){
 foreach($postags as $the_tag){
   if(isset($banners[$the_tag->name])){
      echo $banners[$the_tag->name];
      // break;
   }
 }
}

I did not test this code, on a live wordpress theme, so post what results you get.
 
I forgot about this post... might work better with just isolating the categories. I'll give it a go now.

Smart ads will definitely not do this btw.

Well if its just for one theme then you could iterate over the results of get_the_tags Function Reference/get the tags WordPress Codex

Code:
$banners=Array();
$banners['handbag']='<a href="http://handbags.faux">Buy Hand Bags</a>';
$banners['high.heels']='<a href="http://myclothingshop.faux">Clothing Rocks</a>';
// ....

if($postags=get_the_tags()){
 foreach($postags as $the_tag){
   if(isset($banners[$the_tag->name])){
      echo $banners[$the_tag->name];
      // break;
   }
 }
}
I did not test this code, on a live wordpress theme, so post what results you get.
 
matt3's gives very good info, but his code will output ALL of the matching KW's. if you want to output 1 banner per page then you will have to modify the code with a $key to escape the loop when a KW if found. Or for greater customization you can assign all of the keywords a value(1 for most important, 2 for less.. etc), run the entire loop. Now run another foreach loop on the KW's to find the either the highest ranking KW or the first respective KW in a set of similar ranking kw's.