Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

MyBB forum - How to add Adsense ads

Ads
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#1
Support Team
So finally you have decided to monetize your MyBB forum with AdSense ads but heave a hard time actually achieving that? Don't wary it's actually not that difficult to monetize MyBB forum. There are many plugins that can do it more or less but those plugins can also add more that just ads to our forum they can cause some issues and that is what we are trying to avoid at all cost!

However for this to work you need to have installed Template Conditionals plugin which allows us to use simple Conditional expressions in our MyBB HTML templates

Download Template Conditionals here: http://mybbhacks.zingaburga.com/showthread.php?tid=464


In this tutorial I will should you how to add ads:

1). PART
Inside the first post only
After the first post

After X posts (it will show after whatever the number of posts you want it to show)

2). PART
After X posts on the first page only
After X posts on all the pages except the first one

So lets get started, all the codes have to be added to postbit template which is located in ACP>>Templates & Styles>>Templates>>YOUR TEMPLATES>>Post Bit Templates>>postbit

1). PART

How to add an AD inside the first post. This AD will only show on the first page!

In the postbit template find

PHP Code:
{$post['message']} 

Add this code just after the code above

PHP Code:
<if $post['pid'] == $thread['firstpost'then>
AdSense Code
</if> 

To add an AD after the first post add the code above at the end of the template after </table>

2). PART

Add these codes at the end of the postbit template after </table>

How to show an AD after X number of posts. This AD will only show on the first page!

PHP Code:
<if $postcounter == && $page == 1 then>
AdSense Code
</if> 

Alternately try this conditional

PHP Code:
<if ($postcounter X) % $mybb->settings['postsperpage'] == "0" && $page 1 then>
AdSense Code
</if> 

How to show an AD after X number of posts. This AD will show on all the pages except the first page!

PHP Code:
<if $postcounter == && $page 1 then>
AdSense Code
</if> 

Alternately try this conditional

PHP Code:
<if ($postcounter X) % $mybb->settings['postsperpage'] == "0" && $page 2 then>
AdSense Code
</if> 

Replace X with the post number after which you want this code to be shown!
invisibe_dude Offline referral

Posts: 820
Joined: May 2013
Reputation: 24

#2
Posting Freak
Remember that you have to blend Adsense Ads with your content otherwise it may have a negative impact on your site. Also make sure not to use big Ad Sizes as they are very easy to spot!
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#3
Support Team
That's right Dude the whole point if heaving ads is to make sure you have them well integrated (blended) with your content (ad size, colors, image or text). Remember ad size does matter!
ivan Offline referral

Posts: 713
Joined: Jul 2013
Reputation: 6

#4
Senior Member
Thanks very much Marcus looks great. Can I use this without the template conditionals plugin I don't really like plugins?
destroyer Offline referral

Posts: 430
Joined: Jul 2013
Reputation: 3

#5
Senior Member
I don't think so you need to install a plugin that will interpret PHP conditionals in HTML templates!
antony Offline referral

Posts: 478
Joined: Jul 2013
Reputation: 5

#6
Senior Member
Template Conditionals is great plugin allows to do amazing stuff with your templates. Also there is another great plugin for MYBB which allows you to add and use PHP in your HTML Templates it is called "PHP in Templates and Template Conditionals" and can be downloaded here: http://mybbhacks.zingaburga.com/showthread.php?tid=260
victor Offline referral

Posts: 638
Joined: Jun 2013
Reputation: 33

#7
Senior Member
Pretty need tutorial thanks many will find this useful as many want to make money with their MYBB forum and Adsense!
Evanto Offline referral

Posts: 14
Joined: Jan 2014
Reputation: 1

#8
Junior Member
Can this be done without template conditional plugin and using core MyBB edits ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#9
Support Team
(02-22-2014 09:54 PM)Evanto Wrote:  Can this be done without template conditional plugin and using core MyBB edits ?

Hi buddy unfortunately you can't without some kind of plugin either a simple plugin that will use conditionals described above in my post to add AdSense ads or you'll need template conditional.

Template conditionals for me is the best plugin for MYBB after SEO plugin it allows you to do wonderful things that otherwise will require creating a separate plugin!
victor Offline referral

Posts: 638
Joined: Jun 2013
Reputation: 33

#10
Senior Member
(02-22-2014 09:54 PM)Evanto Wrote:  Can this be done without template conditional plugin and using core MyBB edits ?

I don't recommend core edits specially if you don't know much about PHP and how it works! Plugins not all of them but many are without a doubt much better than core edits!
maya Offline referral

Posts: 1,058
Joined: May 2013
Reputation: 34

#11
Posting Freak
Core edits are better than a plugin because plugins are putting more load on the server!
seo123 Offline referral

Posts: 427
Joined: Mar 2014
Reputation: 16

#12
Senior Member
If you want to add Adsense after first post then simply use this conditional!
PHP Code:
<if $postcounter == 0 then

This will show Adsense after 1, 11, 21..... post
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#13
Support Team
(04-07-2014 07:05 PM)SEO123 Wrote:  If you want to add Adsense after first post then simply use this conditional!
PHP Code:
<if $postcounter == 0 then

This will show Adsense after 1, 11, 21..... post

Your conditional is wrong it should be like this:

PHP Code:
<if $postcounter == 1 then>
//Adsense after first post
</if> 
debdeb Offline referral

Posts: 1
Joined: Dec 2014
Reputation: 0

#14
Junior Member
Hi, do you know how to show adsense after X portal_announcements in portal template?

I tried with:

PHP Code:
<if (($announcementcount 5) % $pages == 0then> ... </if> 

and

PHP Code:
<if $announcementcount == && $page == 1 then>... </if> 

without success..

Thank you
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#15
Support Team
postbit posts have numeric value assign to them portal announcements are not so you would need to create a plugin hook it to portal to count the threads then show some code in this case Adsense after the X amount of threads!

Here is a plugin buddy!

PHP Code:
<?php

if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("portal_announcement""adsense");

function 
adsense_info()
{    
    return array(
                
"name" => "Adsense in portal",
                
"description" => "Shows adsense ads after x posts",
                
"website" => "http://letsforum.com",
                
"author" => "Letsforum",
                
"authorsite" => "http://letsforum.com",
                
"version" => "1.0",
                
"compatibility" => "16*"
            
);
}

function 
adsense()
{
if (!isset(
$portalcounter)) {
    
$portalcounter 0;
}
$portalcounter++;
}
?>

Save it as adsense.php then upload it to inc/plugins directory then activate from Admin Control panel!

Now you can use this template conditional in the portal_announcement template!

PHP Code:
<if ($portalcounter 6then><else>
    
ad code
</if> 

This will show ad code after the 6th announcement!





User(s) browsing this thread: 1 Guest(s)