Home > Wordpress > Scripts to Display Ads in Blogs based on the Author of the post

Scripts to Display Ads in Blogs based on the Author of the post

Today I was asked about whether there was a plugin or script enabling show advertising to show a particular entry depending on the author to write it. The question certainly seemed interesting, so I coded a quick bite for those who wish to review or implement it on your blog.

Google Adsense logo

Certainly I would not complicate life with arrangements or something more elaborate or optimized , but I guess if there are few authors in a blog ( up to 6) with a daily average visits , the following code will work fine :

<? php $ mi_autor=get_the_author_meta(' user_login '); ?>
   <? php
       switch($ mi_autor){
       case "Admin":
         print (' Code advertising User admin ');
         break;
       case " otroautor ":
         print (' Code advertising otroautor user ');
         break;
       default:
         print (' Code advertising shared ');
         break;
  }
  ?>

You must install the file single.php of your blog , just where they want to be displayed advertising. As generalva under the title of the post or other place over in the sidebar, is up to you .

If you use Adsense or similar should not have problems around the repetition of Ads various advertisers (not to lower your CTR), since the conditions are mutually exclusive , as well as run from the server side , so users are not able to see this code but only its execution.

The code has been implemented using the principal author’s name (called admin default) and another, which called otroautorBut you can add the case they’re needed. The latest case , called default , I suggest not to touch it because it is executed when none of the above conditions are met, so that functions as a control.

I preferred to use the code name by which users do login before doing that with the normal ID, because many do not understand what 1 .- 2 .- where to find it . For those who have questions or want to keep trying harder, for example using probabilities, they left a couple of links Codex WordPress.

Related posts:

  1. Useful WordPress Plugins for Business Blogs
Categories: Wordpress Tags:
  1. No comments yet.
  1. No trackbacks yet.