Quote:
Originally Posted by tbworld
See ... Admin Control Panel --> Plugins and Products (Sidebar Menu) --> Add New Plugin.
Product: vbulletin
Hook Location: postbit_display_complete
Title: Postbit Post-Per-Page Counter <-- or whatever
Execution Order: 5
Plugin PHP Code:
PHP Code:
// Hook: postbit_display_complete
if (THIS_SCRIPT == 'showthread')
{
global $tbworld_postbit_postcount;
vB_Template::preRegister('postbit_legacy',array('tbworld_postbit_postcount' => ++$tbworld_postbit_postcount));
}
Plugin is Active : Yes
This is just a simple counter that counts post per page.
|
Quote:
Originally Posted by tbworld
So what should be happening is that in the "islastshown" conditional, I have added an additional check to see if the post count on that page is equal or greater than 3. If it is not then do not show the ad. Simple.
|
Brilliant! This is working perfectly. :up:
Until now, I have not used plugins in this manner. I've tested this in a thread, and have verified that if there were less than 3 posts only the single ad was shown. For anyone else considering making their ads work the way mine here, here's the complete code below.
These are my conditions:
1) The ads will ONLY be shown to unregistered / guest users and a couple other groups - as indicated by the <vb:if condition="is_member_of($bbuserinfo,1,3,4,8) section
2) There are TWO Google AdSense ads created, "vBulletin Forum Ad after First Post" which is shown after the opening post and "vBulletin Forum Ad Before Last Post" which is shown ONLY in a thread if there are 3 posts.
In postbit_legacy:
HTML Code:
<vb:if condition="is_member_of($bbuserinfo,1,3,4,8) AND $post['isfirstshown']">
<li class="firstpost_advert_container"><div class="firstpost_advert">
<vb:literal>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- vBulletin Forum Ad after First Post -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-***************"
data-ad-slot="**********2"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</vb:literal>
</div>
</li>
</vb:if>
<vb:if condition="is_member_of($bbuserinfo,1,3,4,8) AND $post['islastshown'] AND $tbworld_postbit_postcount >= 3">
<li class="lastpost_advert_container"><div class="lastpost_advert">
<vb:literal>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- vBulletin Forum Ad Before Last Post -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-************"
data-ad-slot="*************"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</vb:literal>
</div>
</li>
</vb:if>
Also, ad the "containers" that will show the ads in the threads (add this to additional.css in your style). Your border colors and sizes may vary.
HTML Code:
.firstpost_advert_container {
clear: both;
display: block;
float: left;
margin-bottom: 12px;
position: relative;
width: 100%;
border: 1px solid #666666;
}
.firstpost_advert {
with: 100%;
background: #666666;
border: 1px solid #666666;
min-height: 90px;
margin: 0;
padding: 7px;
text-align: center;
vertical-align: middle;
}
.lastpost_advert_container {
clear: both;
display: block;
float: left;
margin-bottom: 12px;
position: relative;
width: 100%;
border: 1px solid #666666;
}
.lastpost_advert {
with: 100%;
background: #666666;
border: 1px solid #666666;
min-height: 90px;
margin: 0;
padding: 7px;
text-align: center;
vertical-align: middle;
}
Lastly, in order for the part where only threads with several replies will show BOTH the firstpost_advert and the lastpostadvert, add the plugin that tbworld provided above.