06

Mar

Quick and dirty way to show random banners

Posted by stuart as php, advertising

If you look to your right (site visitors only), you’ll see that I’m thinking about re-introducting ads on this blog.

It’s just something I’m toying with, they’ll be gone in a week or two if I decide that they’re not worth it.

Initially I just threw up AdSense, the old chestnut that it is, but I thought it might be nice to try to show some other ads as well. I know there are probably plugins out there that randomise the showing of banner ads, but I reckon the way I’m going to show you is quicker and simpler (plus, how do you know, I mean really know, that the author of that plugin is not showing their own ads from time to time on your blog?)

So all you’ll need to do is grab some ad code from your affiliate programm / PPC /CPM or whatever ad network you’re using, and copy and paste the following code into a text editor:

<?php

$adid = rand(1,2);

if ($adid == 1) {

echo ‘ad 1 code‘;

}

else

{

echo ‘ad 2 code’;

}

?>

Replace the ‘ad code 1′ and ‘ad code 2′ bits with your own ad display code (leaving the single quotes intact), and paste the whole lot into your blog theme where you want the ads to show.

Hit reload on this page a couple of times if you want to see it in action, I have an AdSense and Amazon ad rotating at the moment.

8 comments so far

Useful info out here ;)

As far as I can remember, I think it’s against adsense policy to rotate other ads in the same spot. Am I misinformed?

Hey stuart. intoduce some ads, people need feeding :)
you blod is clean and tidy with space for some ads without detracting from your posts. And the code is useful, thanks

Thanks for the helpful information. Hope I can get the hang of it.

That’s pretty cool. You ought to have ads on this blog. Your regular readers don’t really care. It’s mainly se traffic that will click on them anyways. I’ll try the code thingy.

:O)

[…] Quick and dirty way to show random banners Initially I just threw up AdSense, the old chestnut that it is, but I thought it might be nice to try to show some other ads as well. I know there are probably plugins out there that randomise the showing of banner ads, but I reckon the way I’m going to show you is quicker and simpler (plus, how do you know, I mean really know, that the author of that plugin is not showing their own ads from time to time on your blog?) […]

It’s a good way of finding a new way of advertising on the internet. There are a lot many new websites on the internet where we can advertise our ads and a lot of revenue.

Thanks for the information

You have very well put up the article

Leave a Comment:

Name (required)
Mail (will not be published) (required)
Website
Message