View Full Version : conditional ad after 5th, 15th post
Dave-ahfb
04-09-2015, 01:36 PM
I have it working fine after 5 posts with
[code]<vb:if condition="$post['postcount'] % $vboptions['maxposts'] == 5">;/code]
and it puts the 2nd ad under 15 if I change the 5 to 15.
It also places ads under 30 and so on (for those with extended posts per page)
Is there a way to combine the conditional statement to include the ad spots I want like 5, 15, 25, 35 rather than right a new conditional which seems to have less control?
You should be able to do this:
<vb:if condition="in_array($post['postcount'], array(5, 15, 25, 35))">
but then you have to list all positions instead of having them repeat due to the '%'.
Dave-ahfb
04-11-2015, 11:49 AM
That works but not as hoped for.
Lets say I want it after every 10th post regardless of page or post per page count?
Sal Collaziano
09-24-2017, 01:43 PM
I'm curious about this also. I'd like to place an ad after the 3rd post on every page. Is there a solution to do this?
MarkFL
09-24-2017, 02:32 PM
I'm curious about this also. I'd like to place an ad after the 3rd post on every page. Is there a solution to do this?
Create a plugin hooked at "postbit_display_complete" with the following code:
global $ids;
if ($post['postid'] == $ids[2])
{
$template_hook['postbit_end'] .= 'Ad goes here...';
}
Replace 'Ad goes here...' with your ad HTML. :)
Sal Collaziano
09-24-2017, 06:09 PM
Thank you, Mark. Is there a way to get this to work with conditionals? I get:
syntax error, unexpected '<', expecting end of file on line 4 in /home/site/whatever/includes/class_postbit.php(345) : eval()'d code
#0 /home/buickfor/public_html/forums/showthread.php(1096): vB_Postbit->construct_postbit(Array)
#1 {main}
P.S. How was IRMA for you up there?
MarkFL
09-24-2017, 06:17 PM
Thank you, Mark. Is there a way to get this to work with conditionals? I get:
syntax error, unexpected '<', expecting end of file on line 4 in /home/site/whatever/includes/class_postbit.php(345) : eval()'d code
#0 /home/buickfor/public_html/forums/showthread.php(1096): vB_Postbit->construct_postbit(Array)
#1 {main}
What code did you use in your plugin?
P.S. How was IRMA for you up there?
We got a long of wind, but not a lot of rain in my neck of the woods. How did you guys fare?
Sal Collaziano
09-24-2017, 06:22 PM
What code did you use in your plugin?
We got a long of wind, but not a lot of rain in my neck of the woods. How did you guys fare?
I'm trying to use something like this:
<vb:if condition="!is_member_of($bbuserinfo, #,#,#)>
<li class="firstpost_advert_container">
<div class="firstpost_advert">
AD CODE HERE
</div>
</li>
</vb:if>
With Irma, we got a lot of strong wind. Lots of trees blown down. But very luckily, no flooding. None. That was great. I also never lost power. But lost internet for a few days...
MarkFL
09-24-2017, 09:07 PM
The conditional you are using is valid within a template only, however you can exclude usergroups within the plugin PHP code. For example:
global $ids;
$excluded = array(5, 6, 7);
if (!is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
{
$template_hook['postbit_end'] .= 'Ad goes here...';
}
Make sure the HTML you add is within the single quotes...it needs to be a data string.
I prefer using plugins rather than hacking templates, if at all possible. :)
Sal Collaziano
09-25-2017, 12:40 PM
This is my first time using plugins, so please bear with me. :p
Here's what my plugin looks like now:
----- ----- -----
global $ids;
$excluded = array(199, 299, 399);
if (!is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
{
$template_hook['postbit_end'] .= '<li class="firstpost_advert_container"><div class="firstpost_advert">
<div class="firstpost_advert">
<center>
AD CODE HERE
</center>
</div>';
}
----- ----- -----
I'm still doing something wrong with my added code. What sticks out to you? I'm not in any of those user group IDs. Let me know what you think. Thank you very much!
The conditional you are using is valid within a template only, however you can exclude usergroups within the plugin PHP code. For example:
global $ids;
$excluded = array(5, 6, 7);
if (!is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
{
$template_hook['postbit_end'] .= 'Ad goes here...';
}
Make sure the HTML you add is within the single quotes...it needs to be a data string.
I prefer using plugins rather than hacking templates, if at all possible. :)
MarkFL
09-25-2017, 02:12 PM
Did you set the plugin to be active?
Sal Collaziano
09-25-2017, 02:13 PM
Did you set the plugin to be active?
I did, but I didn't see the new ad. But no error message, so that's good. :p
MarkFL
09-25-2017, 02:27 PM
Are you doing this on a live site or a test site?
Sal Collaziano
09-25-2017, 02:29 PM
Are you doing this on a live site or a test site?
Live site...
--------------- Added 1506365510 at 1506365510 ---------------
Oh, my fault. I see what the problem is. It's because I'm trying to use this on my mobile theme. :o Would you show me how to add that into the mix? :p
MarkFL
09-25-2017, 04:58 PM
Live site...
--------------- Added 1506365510 at 1506365510 ---------------
Oh, my fault. I see what the problem is. It's because I'm trying to use this on my mobile theme. :o Would you show me how to add that into the mix? :p
Yes, the mobile style doesn't seem to have any template hooks in the postbit templates. Try adding the following line to the very bottom of whichever postbit template you are using in your mobile style:
{vb:raw template_hook.postbit_end}
Sal Collaziano
09-25-2017, 05:01 PM
Yes, the mobile style doesn't seem to have any template hooks in the postbit templates. Try adding the following line to the very bottom of whichever postbit template you are using in your mobile style:
{vb:raw template_hook.postbit_end}
That did it! Thank you very much! :p I was going to try and hack this:
global $styleid;
if ($styleid == 1){
...into the plugin - but surely would have broken things. :p I appreciate you helping me out with this!
--------------- Added 1506366173 at 1506366173 ---------------
Ahh! Poop! It shows up in my non-mobile style as well. One more? Can you tell me how to prevent it from displaying there? :o
MarkFL
09-25-2017, 05:08 PM
Ahh! Poop! It shows up in my non-mobile style as well. One more? Can you tell me how to prevent it from displaying there? :o
If you only want it to display in your mobile style, change the conditional to read:
if (STYLEID == 2 AND !is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
Sal Collaziano
09-25-2017, 05:11 PM
If you only want it to display in your mobile style, change the conditional to read:
if (STYLEID == 2 AND !is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
Thank you, again. It's so cool all the things you can do with coding knowledge. It's sort of fun and entertaining. :p :)
MarkFL
09-25-2017, 05:16 PM
Thank you, again. It's so cool all the things you can do with coding knowledge. It's sort of fun and entertaining. :p :)
Careful...it can be quite addicting! :eek::D
Sal Collaziano
09-25-2017, 05:18 PM
Careful...it can be quite addicting! :eek::D
I see that! If I weren't so busy I'd get a For Dummies book. :p When I have some free time, I just might...
scottkoz20
11-05-2017, 12:47 PM
Thanks for this thread and Mark and Sal for the discussion
I built a plugin to go after the 5th post of a thread that is displaying based on this information and works flawlessly! :)
EDIT: I might want to dynamically look to add this to the final post on a displayed thread regardless of the number of posts, but this is something I'll deal with later :)
scottkoz20
11-07-2017, 10:54 PM
hmmm - well, I thought it was flawless
when I use the following code (want to do this after post 3, 6 and 10 (I have 3 different plugins) - it is adding addition ads onto the Private Message Inbox in between the message and the Quick Reply section.
I already have 1 add that exist, it's adding 1 for each plugin
not sure how to put in the Not PM page(s) into this code (or to array the posts) as I could remove the Ad code for the PM's and allow this handle it
global $ids;
$excluded = array(88,115);
if (!is_member_of($vbulletin->userinfo, $excluded) AND $post['postid'] == $ids[2])
{
$template_hook['postbit_end'] .= '<center>AD CODE</center>';
}
MarkFL
11-08-2017, 12:11 AM
If you wish to exclude private messages, then add the condition:
THIS_SCRIPT !== 'private'
scottkoz20
11-08-2017, 07:54 PM
you rock!
thanks Mark
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.