selinap.com

To leave furtively and stealthily.

Home » Blog Tips, PHP

Create a Rotating Ads

June 13th, 2008

If you run more than one ads, but lack of space to put the ads, you can actually rotate the ads.

The code below will create a random number from 1 to 10. Since I want both ads to be shown with a probability of 50%, I put the condition if (x > 5). You can change this number.

1
2
3
4
5
6
7
8
9
10
<?php $x = rand(1,10); ?>
<?php if ($x > 5) { ?>
 
<!--your first ad code-->
 
<?php } else {?>
 
<!--your second ad code-->
 
<?php } ?>

You can read more about PHP rand() function here.

Related Articles:

Popular Articles:

Spread/Promote this article.

Digg | Del.icio.us | Stumble | Y! MyWeb | Y! Buzz | Fave It! | Reddit

Subscribe for free.

 Subscribe to Selinap.com feed right now!

 Get Updates by Email

Tags: , ,

3 Responses to “Create a Rotating Ads”

  1. Norhafidz says:

    Nice info there, thanks, I was searching for the code and now I can implement it on my blog! keep giving more helpful information.

  2. KNizam says:

    perghhhhh too techie la for me. hehe :)

  3. selinap.com says:

    KNizam: You just need to copy and paste it to the place where you want it to appear in the template file.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">


© Copyright 2008 - 2009 selinap.com
Entries (RSS) and Comments (RSS).