Archive for the Category »Wordpress «

Simple Banner Rotation in WordPress.

Have a wordpress blog and want to rotate some banners or photos?  Here is a quick and dirty way.

Go to wordpress.org and find a a widget that allows you to post PHP code.  Once you find one you like install it. You can then go to your ->Appearance ->widgets section.  I put the widget in my sidebar.  Once there you can click on the widget and it probably have a Title field which you can call it “Ads” or what ever you need.  Then it will have a text area where you can add some code.  There just put this in:

 

<center>
<?php
$bannerAd[1] = ‘<a href=”http://www.destinationlink/” target=”_BLANK”><img src=”/images/ad1.png”></a>’;

$bannerAd[2] = ‘<a href=”http://www.destinationlink/” target=”_BLANK”><img src=”/images/ad1.png”></a>’;

$adCount = count($bannerAd);
$randomAdNumber = mt_rand(1, $adCount);
echo $bannerAd[$randomAdNumber];

?>
</center>

You can add more by just coping and pasting more of the “$banner….” block of code.  Don’t forget to increment the number that is in the [ ]’s.

Hope it helps!