-- Getting Started -->
The best place to start with Advertwhirl is either the "Simple Ad Rotation" tutorial or the "Sharing Ad Slots With a Guest Blogger" tutorial. They will walk you through getting a campaign setup.
If you'd prefer to just jump in feet first, here is a short checklist to get you going.
Getting Started
- Setup your Ad Sources
- If you use Adsense you can go to "Settings" to configure Advertwhirl to automotically pull in your Adsense Ad Units as Ad Sources
- You can go to "Ad Sources" to configure any other local ads you want
- Create an Ad Campaign
- Setup an Allocation
- Add the ad sources you want the allocation to rotate through
- Set the weights for how you want the ad sources to rotate
- Create any additional Allocations you need (if you want to rotate different sets of ads in different sections of your blog, if you have guest bloggers etc...)
- Add the ad sources you want the allocation to rotate through
- Set the weights for how you want the ad sources to rotate
- Add some rules so Advertwhirl can select which Allocation should fill which Ad Slot
- Place your Ad Campaigns somewhere
- The quickest method is now right in the Campaign Editor, a couple of checks and and Advertwhirl will auto place the campaign where you want.
- The Advertwhirl Campaign Widget under "Appearance" -> Widgets will let you place an Ad Campaign anywhere you can put a sidebar widget
- The Advertwhirl Shortcode will let you place ads in the Post Editor [advertwhirl campaign="Your_Campaign"]
- The functions advertwhirl_get_ad("Your_Campaign") and advertwhirl_print_ad("Your_Campaign") will let yo precisely place ads, if you are up to the task of editing your themes template files
- You can place ads external to your site through a url using the external ads feature. http://www.yourdomain.com/ads/Your_Campaign
- The "Autoplacing Ad Campaigns" and "Adding Ads to Your Posts" tutorials give more details on how to place your ads
Here are a couple of bullet points to explain how Ad Campaigns are structured. A more detailed explanation can be found in the "Campaigns, Allocations And Rules" tutorial.
Ad Campaigns
- An Ad Campaign fills Ad Slots with Ad Units
- Before you create an Ad Campaign you will need to set up your Ad Sources
- If you use Adsense you can go to "Settings" to configure Advertwhirl to automotically pull in your Adsense Ad Units as Ad Sources
- You can go to "Ad Sources" to configure any other local ads you want
- An Ad Campaign uses rules to match Allocations to empty Ad Slots
- An Allocation rotates Ad Sources based on weight to fill empty Ad Slots
<-- Autoplacing Ad Campaigns -->
<-- Simple Ad Rotation -->
The Situation
You've installed the Advertwhirl ad management plugin for WordPress, You've taken a quick look at Campaigns, allocations and rules still feel a little daunted. All you want to do is rotate ads between adsense and a local banner you have setup for one of your products. You're not quite sure you want to be messing with rules and regular expressions and that other mumbo jumbo.
The Solution
Advertwhirl is quite flexible and lets you manage your advertising campaigns as simply or complexly as you require. If you just want to rotate between a few different ad sources Advertwhirl will help you do that with out the need for any complex configuration.
The Nuts and Bolts
The steps are pretty simple configure Advertwhirl to connect to your Adsense account, add a local ad source for the banner, create an ad campaign with a single allocation that has two ad source(an Adsense Ad Unit and your banner) and no rules. Thats it and this tutorial will walk you through it step by step in less just a couple minutes, unless you are one of those people that tweets everything you do or take a break to become Mayor of this tutorial.
Configure Adsense
Configuring Adsense is super easy. Your Adsense username and your Adsense password are all you need. Lets do it!
- Go to your WordPress blogs admin page
- In the admin "Settings" menu go to the Advertwhirl entry

- Go to the Advertwhirl Settings tab

- Go to the "Adsense Settings" panel right below "General Settings" and fill in your username and password for Adsense and hit Update.
- For security reasons your Adsense password will not be displayed and the field will remain blank if you come back to the settings page in the future. Don't worry it's still there.
- You can leave the other settings alone for now, they won't effect anything you are doing in this tutorial.
That is it. You can now access your Adsense ads directly in Advertwhirl, as well as your Adsense Statistics.
Add the Banner
Adding your own banner is just as easy as setting Advertwhirl up to use Ad Sense.
- Go to the "Local Ads" tab next to the "Settings" tab on the left.
- Click on the "Ad Source" Button

- Fill in a name for your banner, this is what will appear in the dropdown list when you go to add it to your Allocation later.
- Fill in any notes to yourself in the Description field.
- Change the type from Ad Type from "URL" to "Inline Code"
- Paste the html for your banner into the Inline Code textarea
- Click "Add Source" to save your changes

The code I use in the the image consists of two parts, you can use to get you started if html is not your thing-diggity.
The first bit is only appropriate if you have Google Analytics setup for your site. If so you can paste your GA code in place of mine or you could modify mine. I am using Asynchronous Tracking. If you don't have Google Analytics setup for your site or you don't want to track the banner you can go ahead and skip this part and go onto the next bit.
If you use the Asynchronous Tracking code below you need to replace UA-XXXXX-X with your web property id. You can find it by logging into your Google Analytics Account, the web property id for each of your web profiles is listed to the right of the profiles name.
You will also need to replace ".YOURDOMAIN.COM" with the domain for your web profile. The stuff to the left of the "www", don't forget the first "."!
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', '.YOURDOMAIN.COM']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The second bit of code in my local ad is for the banner itself. Again, if you have your own html you wish to use go ahead. This is just here for those needing a hand getting started.
The following code will display a banner image and open a link when the visitor clicks the image.
Use this one if you want the link to open in the same window/tab as the one where the image is displayed. This will take the visitor away from the post where the ad is displayed.
<a href="LINK_WHERE_YOU_WANT_BANNER_TO_GO"><img src="LINK_WHERE_THE_BANNER_IMAGE_LIVES" alt="" /></a>
Use this one if you want the link to open in a new window or tab and leave the visitor on the post where the ad is displayed.
<a href="LINK_WHERE_YOU_WANT_BANNER_TO_GO" target="_blank"><img src="LINK_WHERE_THE_BANNER_IMAGE_LIVES" alt="" /></a>
Which either one you choose to use there are two parts that need to be changed. The instructions are exactly the same for both.
- Change "LINK_WHERE_YOU_WANT_BANNER_TO_GO" to the URL for the web page you wish to open when the banner is clicked. In the example image I the banner for Advertwhirl open the plugin page for Advertwhirl ("http://wordpress.org/extend/plugins/advertwhirl/")
- Change "LINK_WHERE_THE_BANNER_IMAGE_LIVES" to the location of the banner image on your website, or whatever site it is located on. In the example image the banner is located on the Mobile Sentience website("http://www.mobilesentience.com/banners/advertwhirl-take-charge-468x60.png")
Don't forget to leave the quotes.
That's it. Time to create the campaign.
Create the Ad Campaign
Adding your own banner is just as easy as setting Advertwhirl up to use Ad Sense.
- Go to the "Campaigns" tab next to the "Local Ads" tab on the left.
- Click on the "Ad Campaign" Button
- Give the Campaign a name. This is how you will identify which Campaign you wish to use to fill an Ad Slot.The name shouldn't have any spaces or special characters.
- Put any notes which will help you remember what the purpose of this Campaign is in the Description field
- There is already an Allocation created for you and all you will be needing is the one.
- Fill in a Description for the Allocation if you want. It's just a way for you to keep track of what is what in complex configurations. For this simple one it won't really be helpful and you can leave it blank if you want.
- Select the Adsense Ad unit that you wish to use
- Click "Add Advertisement Source"
- Select your banner ad.
- Set your weights. By default the weights are both 1, meaning every other Ad Slot will be filled either with an Adsense ad or your banner. In the example photo I set a weight of 3 for the Adsense ad and 1 for the banner ad. So 3 Ad Slots would be filled from the Adsense Ad Sourcce then 1 from the local banner Ad Source. Another way to look at it is with a 1-1 weight 50% of the Ad Slots are filled from each source and with a 3-1 75% are filled with the Adsense Ad Source and 25% with the local banner Ad Source.
- Click "Save Campaign" and you are done
Displaying Your Ads
Everything is configured and done, but I suppose you're interested in using what you setup.
You have a few options
If you just want to get going with as little hassle as possible you can put a shortcode in your posts where ever you want ads from your new Campaign to appear. The shortcode is listed below, you will need to change YOUR_CAMPAIGN to the name you gave the Campaign in step 3 of creating the campaign.
[advertwhirl campaign=YOUR_CAMPAIGN]
If you don't want to display the ads in your posts but would rather put them in your sidebar you can use the Advertwhirl widget. Just add it to a sidebar or anywhere else in your theme where widgets are enabled and select the campaign you which it to display ads from.
Or, if you are adventurous you can read the more advanced tutorial "Automatic Insertion of Advertisements in WordPress Posts" on how to modify your theme template files to automatically insert your ads from your new Campaign in your posts.
Download Advertwhirl
[download id="4" format="2" autop="false"]
References
Mobile Sentience Advertwhirl page
Advertwhirl in the WordPress gallery
Tutorial with instructions for installing Advertwhirl Plugin
Automatic Insertion of Advertisements in WordPress Posts
Campaigns, Allocations and Rules oh my!
<-- Sharing Ad Slots With a Guest Blogger -->
The Situation
You've installed the Advertwhirl ad management plugin for WordPress, perhaps using the installation instructions in this tutorial. You powered through the campaigns, allocations and rules tutorial and setup your first campaign. You modified your blogs theme to automatically insert advertisements from your campaign in your blog posts.
The world is good, you're successfully monetizing your blog and getting ready to make a big push to expand your viewership. And then a pesky guest blogger asks for a share of the ad slots for any posts she writes. She's made a compelling argument, and your only retort is "er...durrr... But, I don't know how to do that."
The Solution
Advertwhirl is quite flexible and lets you manage your advertising campaigns as simply or complexly as you require. Ad sharing for guest bloggers is one of the easiest configurations you can do with Advertwhirl.
The Nuts and Bolts
The steps are pretty straight forward and not all that different then the "Simple Two Affiliate Ad Rotation" tutorial. Setup your ads, create a campaign with two allocations, one for posts written by your guest blogger and on for any other posts. Set the weights and ad a rule and you're good to go.
Setup the Advertisements
Setting up the ads is only slightly more complicated then in the "Simple Two Affiliate Ad Rotation" tutorial. You need to ad your ads and your guest bloggers ad.
First lets setup your ads using adsense. If you don't use adsense you can follow the steps for setting up a local ad source for your guest blogger to setup a local ad source for yourself.
Here is a recap of configuring Adsense from the "Simple Two Affiliate Ad Rotation" tutorial. All you will need is your Adsense username and your Adsense password.
- Go to your WordPress blogs admin page
- In the admin "Settings" menu go to the Advertwhirl entry

- Go to the Advertwhirl Settings tab

- Go to the "Adsense Settings" panel right below "General Settings" and fill in your username and password for Adsense and hit Update.
- For security reasons your Adsense password will not be displayed and the field will remain blank if you come back to the settings page in the future. Don't worry it's still there.
- You can leave the other settings alone for now, they won't effect anything you are doing in this tutorial.
Now that Adsense is setup lets get a local ad setup for you guest blogger.
Adding an advertisement for your guest blogger is just as easy as setting Advertwhirl up to use Ad Sense. There are two options at this time. If your guest blogger provided you with html or javascript code use option one, if she gave you a url option two is what you'll want.
Option one to create a local ad from html or javascript code.
- Go to the "Local Ads" tab next to the "Settings" tab on the left.
- Click on the "Ad Source" Button

- Fill in a name for your guest bloggers advertisement, this is what will appear in the dropdown list when you go to add it to your Allocation later.
- Fill in any notes to yourself in the Description field.
- Change the type from Ad Type from "URL" to "Inline Code"
- Paste the html/javascript code your guest blogger gave you into the Inline Code textarea
- Click "Add Source" to save your changes

Option two to create a local ad from a url.
- Go to the "Local Ads" tab next to the "Settings" tab on the left.
- Click on the "Ad Source" Button

- Fill in a name for your guest bloggers advertisement, this is what will appear in the dropdown list when you go to add it to your Allocation later.
- Fill in any notes to yourself in the Description field.
- Leave the Ad Type set to "URL"
- Check "wrap in iframe"
- Paste the url your guest blogger gave you into the url textarea
- Click "Add Source" to save your changes

That is it, your ads and your guest bloggers ads are now setup and you are ready to rock onto the next step.
Create the Campaign
Creating an ad campaign for guest bloggers takes only slightly longer then setting up"Simple Two Affiliate Ad Rotation" and is really no more difficult. You will need at least two allocations. One allocation for each of your guest bloggers and one allocation for all posts not written by a guest blogger.
- Go to the "Campaigns" tab next to the "Local Ads" tab on the left.
- Click on the "Ad Campaign" Button
- Give the Campaign a name. This is how you will identify which Campaign you wish to use to fill an Ad Slot.The name shouldn't have any spaces or special characters.
- Put any notes which will help you remember what the purpose of this Campaign is in the Description field
- There is already an Allocation created for you, use this one for your guest blogger.
- Fill in a Description for the Allocation if you want. It's just a way for you to keep track of what is what in complex configurations. For this simple one it won't really be helpful and you can leave it blank if you want.
- Select the Adsense Ad unit that you wish to use for your share of the ads in any of your guest bloggers posts.
- Click "Add Advertisement Source"
- Select your guest bloggers ad.
- Set your weights to match the agreement you have with your guest blogger.
- Click "Add Rule Set"
- Select "Match an author" and click "Add Rule"
- In the newly added rule select the name of the guest blogger from the drop down list.
- Click "Add Allocation"
- Use this allocation for any posts not written by your guest bloggers.
- Fill in a Description for the Allocation if you want.
- Select the Adsense Ad unit that you wish to use for any posts not written by your guest bloggers.
- Click "Save Campaign" and you are done
Thats it. Any posts written by the guest blogger will rotate ads based on the weights you configured. Any other post will serve only your ad unit. If you have multiple guest bloggers the process is the same. Just add an allocation for each that is configured the same as Allocation 1, just change the weights, the authors ad unit and who the author is. Make sure to leave the Allocation with no rules and only your Ad Unit as the last allocation.
<-- Campaigns, Allocations And Rules -->
The Situation
You've downloaded Advertwhirl from WordPress plugin gallery after reading its quite impressive description and being blown away by its screenshots. You go to the settings and are at a loss as to where to even begin.
The vast list of what you can do with Advertwhirl also can make getting started a daunting task. Most of the settings are fairly intuitive but the meat of Advertwhirl is Ad Campaigns which ironically enough is also the part that gives people the most trouble, ok maybe not so ironic.
The Solution
Read this tutorial. Seriously, thats it. It also wouldn't hurt any to make a test campaign and a test post add an ad slot to the test post with a the short code and play around with the rules and allocations until you have a grasp of things. If you still have any problems or usage questions you can ask them on the Advertwhirl Support Forum.
The Nuts and Bolts
Terms
Below are a few terms you should be familiar with before diving into the different sections.
- Ad Campaign - A collection of ads and rules which are assigned to ad spots.
- Ad Slot - a spot in a blog page or post where an ad is displayed.
- Ad Source - A source of ad units to fill ad slots with. This could be a static local banner, Adsense ads, Groupon ads etc...
- Ad Unit - The ad that fills an ad slot during a particular view of a page or post
- Allocation - a collection of ad sources paired with weights which determine the ratio of how the ad sources are rotated to fill an ad slot with an ad unit.
- Rules - rules determine which allocation is selected to fill an ad slot
- RuleSets - Rules are grouped together in rule sets to form complex logic for selecting an allocation
Understanding Campaigns
Campaigns are a collection of ad allocations which share an ad slot(or slots) in your blog. An example would be a campaign for your Blog with allocations setup for your posts and for each of your guest bloggers.
Understanding Allocations
An allocation is composed of two parts, Rules and Ad Sources.
An allocations rules determine whether it matches a particular view of a blog post or page and whether or not that allocation should be used to determine which add will fill an Ad Slot for that view.
If an allocations Rules match and the allocation is used to fill an ad slot the allocations Ad Sources are used to fill the slot. The Ad sources are rotated based on their weight. The rules for rotation are fairly straightforward
- If twenty ads have been filled (across all campaigns) since the last sponsor ad has filled an ad slot the slot is filled with one of the sponsor ads.
- If the first Ad Source has filled fewer ads then its weight it is used to fill the ad slot.
- If the first Ad Source has filled its weight in ads check the next Ad Source as in step 2
- If all the Ad Sources have filled their weight reset their counters to zero and fill the slot with an ad from the first ad source.
See pretty simple. There are a few notes to be aware of but they don't really change the process.
- If there is only one Ad Source it will be used to fill every ad slot for that allocation, excepting of course the sponsor ads.
- You can specify the weight for an Ad Source by weight or percent
- If you mix weights and percents in a single Allocation the total of all percent weights must be less then 100% to allow for the Ad Sources with non-percent weights
- If you use only percentage weights in an Allocation then the total of weights must be 100% no more, no less. 100% shall be the total weight, and the number of the weighting shall be 100%. 101% shalt not be the weight, neither 99%, excepting that thou then proceed to 100%. 105% shall be right out.
- MATH WARNING scary I know. If you mix weights and percentage weights the weight used in the above rotation algorithm is determined by totaling the percentage weights and totaling the straight weights. The calculated total weight of all the Ad Sources is the total of the straight weights divided by 1 - (the total of the percentage weights divided by 100) . The calculated weight for any Ad Source with a percentage weight is the calculated total weight multiplied by the Ad Sources percentage weight divided by 100.
- Example: you have an allocation with 3 Ad Sources. The first has a weight of 2, the second a weight of 5 and the third a weight of 30%. The third Ad Source will have its ads rotated using a weight of 3. MORE MATH 2 + 5 / (1 - .3) = 7 / .7 = 10. 10 * .3 = 3
- The actual math used is a little come complicated to keep the calculated weights for Ad Sources with percentage weights accurate(odd percents can lead to a weight of 2.7 for instance and how exactly you fill .7 of an Ad Slot is beyond me) by adjusting the order of magnitude for all weights to eliminate non-repeating decimal weights and then factoring the weights so the first Ad Source doesn't have to fill 1000 slots before the second Ad Source is used. I won't go into the exact math though as the Euclidean algorithm for finding the Greatest Common Factor is beyond the scope of this tutorial.
Understanding Rules
Rules are simple and powerful, just not 100% self explanatory. An Allocation can have zero or more rules grouped together in RuleSets. An Allocations rules determine whether or not an the Allocation is used to fill an Ad Slot or not. When an Advertwhirl tries to fill an Ad Slot the Allocations for the campaign assigned to that Ad Slot are checked to see if the Allocation matches. Starting with the Allocation 1 and working its way down. Once an Allocation matches it is used to fill the Ad Slot and no further checking is performed. The method used to determine if an Allocation should fill an Ad Slot or not is below.
- If the Allocation has no RuleSets it matches. (To insure that a campaign always fills its Ad Slots ad an Allocation at the end of all the others with no rules. If nothing else matches it will)
- If the Allocation has 1 or more RuleSets check each RuleSet to see if the RuleSet matches.
- A RuleSet matches if all if its Rules match
- If any RuleSet matches the Allocation matches and no further checking is performed.
- If no RuleSets match the Allocation doesn't match and Advertwhirl moves on to checking the next Allocation
- If no Allocations match Advertwhirl checks to see if you have "fill empty ad slots" checked in settings and fills the slot with your default ad source
- if "fill empty ad slots" isn't enabled or you don't have a default ad source defined the Ad Slot remains empty (in other words no Ad Unit is displayed there for that view)
The simplified version
- An Allocation matches if ANY of its RuleSets match
- A RuleSet matches if ALL of its rules match
For those of you with programming experience or math logic experience the RuleSets are compared with the equivalent of an OR and the rules in each as with an AND.
Here are the Rules
Author Rule
The author rule lets you select an allocation based on the author of post or page. If the post or page containing the Ad Slot needing to be filled was written by the selected author the rule matches. If not, well it doesn't.
Post Type Rule
The post type rule lets you select an allocation based on the type of the post/page containing the Ad Slot. If you want an Allocation to only be displayed on posts add a Post Type rule set to Post. Want to only display the Allocation to be fill slots on page set the rule to Page.
Category Rule
The category rule matches post/page categories in a little more advanced way than the author and post type rules. The Allocation will fill the ad slot if the post "is a" or "is not a" category. If you select "is a" the Allocation matches if the post has the selected category set or child, grandchild category set. The drop down to select category shows the relationship between categories. Child categories are below and indent from their parent. In other words the indented categories are considered to be "is a" of their parent/grandparent categories. If you select "is not a" it works the same only the Allocation will fill a post if it doesn't have the category or any of its descendants set.
Tag Rule
The tag rule works just like the category rule, only since tags don't have parent/child hierarchies "is a" matches if the post has the tag set and "is not a" matches if the post does not have the tag set.
Location Rule
The location rule matches the visitors location. To use the location rule you need a free api key from the IP Info Database. You can request your key here it is a simple form and they will email the key in a few minutes time. Once you have the key enter it in the "IP Info Database Key" field in General Settings.
Location rules have 3 settings. The first sets which part of the visitor's location you are trying to match. It is possible to match the visitor's Country, State/Region, City or Postal Code.
The next setting is the type of match you want to perform. The types of matches are "is", "is not", "matches regular expression", "does not match regular expression".
The third field is the value you are trying to match.
If you made the following location rule "Country" "is" "United States" the rule would match if the visitor is located in the United States otherwise it would not match.
If you made the following location rule "City" "is not" "Denver" the rule would match if the visitor is not located in the Denver otherwise it would not match.
Regular expressions are an advanced way of matching a pattern, such as "802[0-9][0-9]" is a regular expression that would match a 5 digit number(looks like a postal code, doesn't it?) that begins with 802 and ends with any two digits.
Regular expressions are a complex and advanced subject the surface of which can't even be scratched here. There are a ton of source that our good friend Mr Google can point you to. Or if there is a particular pattern you want to match for one of your rules you can ask on the Advertwhirl support forum.
Link Argument Rule
The link argument rule matches get arguments encoded in a URL. It is used mainly for external ads to allow you to differentiate external ad slots. Get arguments are the part of the link that follow the page. The page and get arguments are separated by a question mark. The following example link has 2 get arguments
http://www.yourdomain.com/advertwhirl/your_campaign?argument1=some_value&argument2=another_value
the two arguments are "argument1" and "argument2" and have the values "some_value" and "another_value".
Like the location rule the link argument rule has three parts. The name of the get argument you want to test, the type of test and the value you want to test against.
the test types are "is equal to", "is not equal to", "is greater than", "is less than", "is greater than or equal to", "is less than or equal to", "matches regular expression", "doesn't match regular expression"
All of the equality tests (everything but the 2 regular expression tests) do a normal numerical compare if the link argument contains a numeric value. ie.. 1 is less than 5, 4 is greater than 3 etc...
If the link argument does not contain a numeric value the equality tests do an alphabetic test. Greater than means the value comes the argument value comes alphabetically after the test value. "apple" "is less than" "banana", "dog" "is greater than" "cat" (and not just because dogs are awesome and cats are snobby little creeps).
Virtual Path Rule
The virtual path rule is only enabled if you have the Virtual Theme plugin installed. The virtual path rule has 2 settings, the test type and the test value. The test types are "is", "is not", "matches regular expression", "does not match regular expression".
Custom Variable Rule
The custom variable rule is only enabled if you have the Virtual Theme plugin installed and works exactly like the link argument rule but instead of matching get arguments it matches Virtual Theme custom variables.
Download Advertwhirl
[download id="4" format="2" autop="false"]
References
Mobile Sentience Advertwhirl page
Advertwhirl in the WordPress gallery
Tutorial with instructions for installing Advertwhirl Plugin
<-- Adding Ads to Your Posts -->
The Situation
You've been adding advertisements to your blog posts with a short code using the built-in editor ie... [advertwhirl campaign=your_campaign]. It was a simple solution to get started and didn't require any editing of your theme templates. But, you've decided the best way to monetize your blog is to put ads in every post and remembering to insert the short code sometimes just doesn't happen.
The Solution
Modify your theme's single.php template file to easily insert an ad campaigns ads automatically in each post. Use allocation rules to determine which ads get inserted into which post while insuring that every post gets an appropriate ad and maintaining the consistency of your advertising campaign.
The Nuts and Bolts
While the modification of a themes template files isn't for the faint of heart and is generally reserved for advanced users inserting and Advertwhirl ad into your post automatically is a pretty straightforward endeavor that can be accomplished by most anyone if they only have a little confidence.
Using the Built-in Theme Editor
WordPress has a theme editor that lets you edit your themes template files right through your blogs admin control panel. To get to the theme editor go to the "Appearance" menu and select "Editor"
Once you have the theme editor open go to the upper right hand corner and select the theme you want to edit. This should match the theme you are using for your WordPress site. For this demo we will be editing the default "Twenty Ten" theme.
Right below where you selected your theme you will find a list of templates for the theme. Click on single.php, this is the template file for single posts.
Find the_content()
Time to put on your brave face and do a little poking around. You are looking for a line that reads "the_content()" in many themes you will find it directly in single.php. In some, such as "Twenty Ten" single.php will load another template part that contains "the_content".
Here is the line you are looking for
<?php the_content(); ?>
If your template for posts is loading a template part which contains the_content you will find a line that has "get_template_part('some_value', 'some_other_value');" and you won't find a line with "the_content();". If single.php does have a line that says "the_content();" and also "get_template_part('some_value', 'some_other_value');" don't worry about the get_template_part line, you can just ignore it. If you don't find "the_content()" you will want to open the template part. The template part you want to open will be composed of the two parts in get_template_part.
<?php get_template_part('loop', 'single') ?>
In the "Twenty Ten" theme single.php loads a template part named loop-single.php
If your theme has "the_content();" you are ready to go, if not open the template part. In the case of the "Twenty Ten" theme you want to open loop-single.php.
Once you find the content you can insert the ad campaign at the beginning or end of the post content. Or if you are a particularly brave soul you can insert the add in the middle of the content.
Insert advertisement before or after post content - Beginners method
The easy method is to insert the "advertwhirl_print_ad();" function before or after "the_content();" The example below will add an advertisement from the "Your_Campaign" ad campaign before and after the post content. You will want to change "Your_Campaign" to match the name of your campaign. If you don't want to immediatly print the ad to the visitors browser but need to do something more with it first you can save the ad to a string with "advertwhirl_get_ad()"
<?php
advertwhirl_print_ad('Your_Campaign'); // This advertisement will be before your post content
the_content();
advertwhirl_print_ad('Your_Campaign'); // This ad will be after your post content
?>
<?php
$ad = advertwhirl_get_ad('Your_Campaign'); // The content of the advertisement will be saved to $ad as a string
$ad = str_replace($what_you_are_looking_for, $what_you_want_it_to_be, $ad); // Change the ad content somehow, prehaps customize it for the visitor
$echo $ad; // This will actually place the customized ad
the_content();
echo advertwhirl_get_ad("Your_Campaign"); // This is exactly the same as advertwhirl_print_ad('Your_Campaign'); and placed the ad after your post content
?>
Insert advertisement in the middle of your post content - Advanced method
The advanced method really isn't so difficult, it just has a few more steps then the beginners method. The code that Mobile Sentience is using to insert ads in the middle of its posts is a variation of the code found in this excellent post at zedomax.biz.
The first step is to make sure you place all the code between the <?php and ?> tags that are surrounding the_content();. If your theme has them all on one line break them up now, also comment out the_comment(); command while you are at it by putting // before it. Make this
<?php the_content(); ?>
look like this
<?php
//the_content();
?>
Now add the code to insert your advertisement in the middle of the post content.
This is what you want to end up with
<?php
//the_content();
$adsEvery = 4; // How many blocks between each of your ads. The smaller the number the more ads, the larger the fewer
$maxAds = 2; // The maximum number of ads to put in a post. There is no maximum if $maxAds is -1
$content = apply_filters('the_content', $post->post_content); //get the post content store in $content
$paragraphs = explode("</p>", $content); //Separate the content into blocks
echo '<div>';
$blockCount = 0; //this is count for number of blocks
$adCount = 0; //this is a variable to keep track of how many ads have been put in the post
foreach($paragraphs as $paragraph) {
if(preg_match('/<p>/',$paragraph) == 0 && $blockCount % $adsEvery == 0 && ($adCount < $maxAds || $maxAds == -1)){
$float = $adCount % 2 == 0?"float:left":"float:right";
echo ' <div style="width: 300px; height: 250px; padding: 9px 9px 9px 9px;">';
advertwhirl_print_ad('Your_Campaign'); // This is what places the Advertwhirl advertisement
echo '</div>';
$adCount++;
}
echo $paragraph; //print the block
echo '</div>';
$blockCount++;
}
echo '</div>';
?>
Thats all it takes. If you want the two lines immediately following //the_content(); can be adjusted to configure how your ads appear.
"$adsEvery" controls how many paragraphs of content are between each ad. The default is to show one ad every 4 paragraphs.
$adsEvery = 4;
"$maxAds" lets you limit how many ads will be displayed in anyone post so you don't overwhelm your readers. Ads lose potency the further down the post they appear and to many can annoy readers. The default is to show a maximum of 2 ads. If you don't want to limit the number of ads that will be shown you can set $maxAds to -1.
$maxAds = 2;
References
Mobile Sentience Advertwhirl page
Advertwhirl in the WordPress gallery
Tutorial with instructions for installing Advertwhirl Plugin
Original advanced method code