Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryMarketing With Software

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Ad Rotator for WordPress and Non-WordPress Sites

This may be the most robust and reliable ad rotation software available. It is strong, sturdy, unlikely to break. Because it's not sophisticated, it's just straightforward code — very little that could break or hide bugs.

It's a simple concept. The software is succinctly written — only about 30 lines of PHP code.

No MySQL woes because none is used.

Your installation is protected by your own server logins. In other words, no extra software logins for hackers to crack.

Oh, and it will rotate any content that can be displayed on a web page. In spite of the software's name, it isn't restricted to only ads.

What I've written sounds like a sales spiel. But it's not. The software is free. It comes with the article.

The software installation is the same for both non‑WordPress and WordPress installations. But inserting the ad rotation into pages differs (one uses a line of PHP code; the other uses a shortcode). And what can be published is slightly different.

To add or remove ads for the rotator, upload or delete ad files in the directory containing the Ad Rotation Software.

Whether WordPress or non-Wordpress, the software needs to be installed before anything else. Let's go ahead and do that.

Installing the Ad Rotator Software

To install the Ad Rotator, follow these steps. (No software customization is required.)

  1. Create a directory on your server for the Ad Rotator. It needs to be a directory exclusively for the Ad Rotator system. We'll call this the "ad rotator directory".

  2. Copy the Ad Rotator source code. Save it as AdRotate.php and upload it to the ad rotator directory.

    <?php
    /*
        Ad Rotator
        Version 1.0
        April 13, 2018
        Will Bontrager Software LLC
        https://www.willmaster.com/
    */
    $SelfFileName = 'AdRotate.php';
    $TrackFileName = 'AdRotate.txt';
    chdir(__DIR__);
    $FileList = array();
    foreach( glob('*') as $file )
    {
        if( ! is_file($file) ) { continue; }
        $ta = explode('/',$file);
        $f = $ta[count($ta)-1];
        if( $f == $SelfFileName ) { continue; }
        if( $f == $TrackFileName ) { continue; }
        $FileList[] = $file;
    }
    $FilesCount = count($FileList);
    if( $FilesCount < 1 )
    {
        echo 'No ad file available.';
        exit;
    }
    $NextFile = 1 + intval(@file_get_contents($TrackFileName));
    if( $NextFile > ($FilesCount-1) ) { $NextFile = 0; }
    file_put_contents($TrackFileName,$NextFile);
    echo file_get_contents($FileList[$NextFile]);
    exit;
    ?>
    
  3. Type the URL of AdRotate.php into your browser.

    If it responds with an error message, then something is wrong with the installation and will need to be corrected. Re-installing should do the trick. Re-copy the source code, saving it as a plain text file named AdRotate.php, and upload AdRotate.php into the ad rotator directory.

    On the other hand, if it responds with "No ad file available" (or with the content of an ad file you may have already uploaded into the directory), then it's working as it should.

  4. The ad rotator directory should now contain a file named AdRotate.txt (the file Ad Rotator uses to keep track of the last ad that was loaded).

    However, if no file AdRotate.txt exists in the directory, then AdRotate.php was unable to create it. In that case, do these two steps.

    1. Create an empty file named AdRotate.txt and upload it into the ad rotator directory.

    2. Give file AdRotate.txt permissions 777.

The Ad Rotator is now installed.

To add ads to the rotator, upload ad files into the ad rotator directory. To delete files from the rotator, delete them from the ad rotator directory.

Publishable Content

Each ad is a separate file. Ads can be any content web pages can use, except one restriction for WordPress installations.

Content TypeWorks On
WordPress
Works on
Non‑WordPress
JavaScriptYesYes
CSSYesYes
PHPNoYes
HTML*YesYes
Plain textYesYes

* Any valid HTML content — videos, images, forms, iframes, textual content, …

Rotating Ads on Non‑WordPress Sites

(Instructions for rotating ads on WordPress sites is in the next section.)

The web page must allow PHP code, a web page file with .php file name extension.

Put this PHP code at the location of the page where you want the rotated ad to publish.

<?php include('http://example.com/place/AdRotate.php') ?>

Replace http://example.com/place/AdRotate.php with the URL to your installation of AdRotate.php in the ad rotator directory.

Rotating Ads on WordPress Sites

(Instructions for rotating ads on non‑WordPress sites is in the previous section.)

Install and activate Insert Here. (Instructions)

Put this shortcode at the place where you want the rotated ad to publish.

[insert_here url="http://example.com/place/AdRotate.php"]

Replace http://example.com/place/AdRotate.php with the URL to your installation of AdRotate.php in the ad rotator directory.

Niceties and Good-to-Know Bits

All ads are individual files in the ad rotator directory. The files contain content that web pages can publish. To publish an image, use an HTML img tag, for example. And JavaScript between script tags. A movie in a video tag. And so forth.

The ad files may have any file name extension you wish, or no extension at all. For personal convenience, naming files with .html or .php extensions may help to recognize the kind of content they contain without manually opening the files.

If you want to insert plain text, put <div style="white-space:pre-wrap;"> immediately in front of the text and </div> immediately after the text. It will provide line breaks without additional HTML markup.

Put new ads into the ad rotator directory from time to time to test how well they work.

Ad click statistics can be obtained by using links generated by Short URL V3. The link counts the click and redirects the browser to it's intended destination.

When click statistics are known, you can replace the low‑producing ads until you end up with only the hightest-producing.

Once you become familiar with the Ad Rotator, I think you'll appreciate how robust it is and how simple it is to use.

"Robust," however, is different than "sophisticated."

For automatic ad click testing — while publishing the more responsive ads more often and publishing the less responsive ads less often — use Carefree Ad Manager. That software also works with both WordPress and non-WordPress sites.

(This article first appeared with an issue of the Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC