An Effective Ad Revenue Sharing System For Multi-Author WordPress Blogs WITHOUT A Plugin
Yo there! If you are new here, you may want to subscribe to my RSS feed, or through email, for more tips on better and effective blogging!
Multi author blogs are all the rage, nowadays. This post is a WordPress tutorial concerning such blogs. I’ve written a tutorial previously too, concerning multi author blogs. This is also part of my tutorials on WordPress. Enjoy this one!
There are many multi author blogs around with paid authors. Posts by different authors have specific ad codes (usually CPC, like AdSense) which are connected to their own accounts, so they make money off clicks on ads contained in their posts.
Many multi-author blog owners implement this system of ad revenue sharing system using a plugin (WordPress), but it is always faster and better to do things using the WordPress core itself, rather than using plugins. This tutorial tells you how to easily implement an effective ad revenue sharing system.
What Will Happen?
What we will do is that we will request from our database, information about the current post. We will then extract the author ID from that information. We will use conditional PHP tags to check this value against a pre-defined set of values (author IDs). If this value matches with any of the predefined ones, that particular author’s ad code is displayed. If the post is by a different author, we display the ad code of that particular author, and so on.
There are, as always, many ways of doing something in WordPress. You can do this via a plugin too, but this is the way I find most efficient…
Let’s Begin
We’ll work in our single.php file. Insert this code where you want the ads to go:
$post_id = $post->ID;
$post_author = get_post($post_id);
$author = $post_author->post_author;
<!–AD CODE FOR AUTHOR 1–>
<?php } elseif ($author == "author-id2") { ?>
<!–AD CODE FOR AUTHOR 2–>
<?php } elseif ($author == "author-id3") { ?>
<!–AD CODE FOR AUTHOR 3–>
. . . .
<?php } elseif ($author == "author-idn") { ?>
<!–AD CODE FOR AUTHOR n–>
<?php } else{ ?>
<!–OTHER CODE–>
<?php } ?>
Edit the Code
Before I explain, you have to edit the code to make it work:
Substitute each entry in bold in the above code with the author ID of each author of your blog, like ...if ($author == "2")… for the author with ID ‘2′ and so on.
Now to explain:
Getting The Author ID
First, we get the current post’s ID ($post->ID) and assign it to a variable ($post_id). Next, we get the post author’s ID by inputting the post ID into the get_post reference function. This reference function is very useful, as it returns many useful attributes about a particular post (like date, author, comment count, etc).
Anyways, we also assign the post author ID to a variable ($author). That’s half the work done.
Checking Using Conditional Tags
Now, in the next step, we check the returned author ID against a predefined value. If it matches, the respective ad code is displayed.
The if ($author == "author-id1“) part checks to see if the value we extracted from the current post’s information matches the predefined value. (Remember to change author-id to the real author ID). If it does (meaning that the post is the author with that ID), the script goes on to display the ad code of that particular author.
To explain, suppose the post was written by an author with ID 5. We already have the value 5 in our code, like so: if ($author == "5"). Now, the author ID we got from the post is 5, right? And it does match up with the standard we set in our code, doesn’t it? So, this script goes ahead, and displays the specific ad code for that particular author.
Now, if the author ID doesn’t fulfill with our first condition, the code continues on, until it finds a match. If it does, it stops right there and displays the specific ad code. If it doesn’t find a match anywhere (.. else {… ), the code does something else (that you specify). Simple as that!
Note: Notice the double equals-to sign (==) there in the code. This is vital: it means that we are comparing the two values. A single equals-to sign would mean we’re assigning a value. That’s not what we need! (This is a blunder committed by so many advanced and beginner coders [including me]! ). Beware of that.
The Benefit of This Solution
The benefit of this solution is that it’s an intelligent script. You just need to fiddle with it once, and it’ll work forever. You could do this using custom fields too, but that would be too clumsy (who wants to add a custom field every time they write a post?)
And if you get more authors, you simply add a few more (copied and edited) lines of code, and that’s it!
What Do You Think?
Do you operate a multi-author blog? Is this tutorial helpful for you? Please do let me know!
And oh, Stumble, Digg, or save this article to Delicious, to let other people know too!
If you liked this post, consider subscribing to the RSS feed (what's RSS?) to get updates on new blog posts.










Hey this is quite informative. I havent seen a tutorial on multi author ad-sharing before.
Multi Author blogs are a good idea as the blog is updated frequently and different authors have different ares of expertise, so that attracts bigger audience!
Great post! Shared with friends!
Digital Musings, thanks for dropping by!
Great writeup on how to do revenue share with wordpress. There is also an API from Google.
Adsense is a great way to generate an income. One site I’ve found to be really useful to make money online is at http://www.flixya.com. Members keep 100% of the ad revenue and you can also make some friends. Its good if you don’t have time to manage your own website.
The google adsense api docs are here: http://code.google.com/apis/adsense/revenuesharing.html
Thanks again for the tips.
the adsense api is great but you have to have substantial traffic to qualify for a key. +100Kpvs
This is a really great solution except for one thing. It seems to make the ad slow to load. Any ideas on how to correct that? I only have it set for three authors right now so I can only imagine how slow it will get with something like 10.
Nice, I haven’t seen a tutorial on revenue sharing plugin. I have only seen the plugin. Thanks for the info