How To Use AdRotator Within Your WordPress Post / Page

By Angsuman Chakraborty, Gaea News Network
Friday, November 17, 2006

AdRotator Overview
WordPress plugin AdRotator enables you to display an advertisement (which is randomly selected from a group of advertisements specified in a text file) at your chosen location anywhere in your WordPress blog (other free WordPress plugins we provide).

Adding ad code is trvial. You simply add this code in your template, where you want to show the advertisement:
<?php echo getad('bannerad'); ?>

It searches for the file wp-content/bannerad.txt, chooses one ad randomly from it and displays it. You should replace bannerad with the name of your actual text file without the ending txt extension.
Ref: AdRotator User Manual

How to display rotating ads directly in your WordPress posts or pages?
The key problem is that WordPress doesn’t allow php code in your posts and pages. And the code above is php code. The solution is very simple.

You should use any one of the available plugins for this. One such plugin is Priyadi’s php-exec. It allows you to execute php code within your posts. To install php-exec follow these simple steps:

  1. Download the plugin: phpexec.txt
  2. Rename the plugin to phpexec.php and put it into your wp-content/plugins directory
  3. Activate the plugin from WordPress administration menu

Now all you have to do is use this code within your WordPress post, to display rotating ads:
<phpcode> <?php echo getad('bannerad'); ?> </phpcode>

Discussion
June 19, 2010: 5:28 pm

thanks for the explanation ;)


Den
February 4, 2009: 7:19 pm

Would it be great if the ads rotates every 5 seconds rather refreshing the page.

November 12, 2008: 2:31 pm

isto deixa o codigo do thema mais limpo… muito bom…


Chaz
March 26, 2008: 8:05 pm

Hi! I am a little confused. I am not finding out how to use your plug in to display graphical ads. From what I read here and in your User Manual, you can only display text ads. What if I wanted to display an animated .gif or .swf file with a link to one of my advertiser’s sites? What information goes in the .txt file?

Also, you say that you can use this anywhere .php is supported. So, how do I use this outside of a blog - on a regular .php page?

December 7, 2007: 9:21 am

You cannot include it in post directly. You have to use a plugin which allows you to insert PHP code within a post or page. You can however use it freely in your template.

December 7, 2007: 9:05 am

I activated the above plug in but whenever I add the addrotator PHP code, wordpress strips it out and makes it a comment.

How do I correct this?

November 21, 2006: 5:17 am

All this is good. But can be exists ad-rotator to show advertising with a binding to categories?

November 17, 2006: 10:21 am

[...] It can also be used to randomly include any other code or even to randomly display images, text messages etc. The usage is limited by your imagination only. You can also use it to display rotating advertisement within your posts or pages. [...]

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :