View Full Version : Need a Condition
Forum-Germany
05-01-2014, 07:56 PM
Hello.
I need a IF-Condition to after every 4th forum (childforumbits) add HTML code.
Example:
- Forum 1
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums ADD HTML-CODE
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums ADD HTML-CODE
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums ADD HTML-CODE
- Forum 2
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums ADD HTML-CODE
-- Sub-Forums
Thanks and best regards.
PS:
Maybe it will help?
<vb:if condition="$GLOBALS[counter]++"></vb:if>
You could try this:
<vb:if condition="($GLOBALS[counter]++ % 4) == 0"></vb:if>
Forum-Germany
05-01-2014, 08:13 PM
Thanks!
My Forum with your Code.
<vb:if condition="($GLOBALS[counter]++ % 4) == 0">TEST</vb:if>
- Forum 1
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
- Forum 2
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
...
...
...
...
- Forum 3
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
So you are getting every 2nd instead of every 4th? Hmm...
Forum-Germany
05-01-2014, 08:51 PM
Yes!
If you would hide the categories, the word "TEST" in every second forum will be displayed.
So yes, you're right.
Can you help me?
I suppose that you could try changing 4 to 8. Edit: But that won't work either, because the counter needs to be reset for every parent forum.
You really should use plugins to handle the counter. Sometimes you can cheat by using ++ in a condition, but it can be complicated to get it to work right.
Forum-Germany
05-01-2014, 09:01 PM
I have found a mistake. Sorry! :D
YES, now the word "TEST" appears in every 4th Forum.
BUT ...
The counter does not include the Forums Category.
Now:
- Forum 1
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
- Forum 2
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
...
...
...
... TEST
- Forum 3
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
So I would like it.
- Forum 1
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
- Forum 2
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
... TEST
...
...
...
- Forum 3
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums
vBNinja
05-01-2014, 09:32 PM
what template did you put that code in?
Forum-Germany
05-01-2014, 10:20 PM
Hello. :)
forumhome_forumbit_level2_post
But does not matter. For it can not work 100% because the counter a) does not include the Forums category and b) the counter after the last sub-forum does not reset.
An example:
(Counter = 0)
- Forum 1
-- Sub-Forums (Counter = 1)
-- Sub-Forums (Counter = 2)
-- Sub-Forums (Counter = 3)
-- Sub-Forums (Counter = 4) ADD "TEST"
-- Sub-Forums (Counter = 5)
Counter Reset: (Counter = 0)
- Forum 2
-- Sub-Forums (Counter = 1)
-- Sub-Forums (Counter = 2)
-- Sub-Forums (Counter = 3)
-- Sub-Forums (Counter = 4) ADD "TEST"
-- Sub-Forums (Counter = 5)
-- Sub-Forums (Counter = 6)
-- Sub-Forums (Counter = 7)
-- Sub-Forums (Counter = 8) ADD "TEST"
-- Sub-Forums (Counter = 9)
Counter Reset: (Counter = 0)
- Forum 3
-- Sub-Forums (Counter = 1)
-- Sub-Forums (Counter = 2)
-- Sub-Forums (Counter = 3)
-- Sub-Forums (Counter = 4) ADD "TEST"
Counter Reset: (Counter = 0)
- Forum 4
-- Sub-Forums (Counter = 1)
-- Sub-Forums (Counter = 2)
Counter Reset: (Counter = 0)
- Forum 5
-- Sub-Forums (Counter = 1)
-- Sub-Forums (Counter = 2)
-- Sub-Forums (Counter = 3)
-- Sub-Forums (Counter = 4) ADD "TEST"
-- Sub-Forums (Counter = 5)
-- Sub-Forums (Counter = 6)
-- Sub-Forums (Counter = 7)
-- Sub-Forums (Counter = 8) ADD "TEST"
vBNinja
05-01-2014, 10:40 PM
yea you're gonna need a plugin
Zachery
05-02-2014, 03:40 AM
why not just put the ads in the description boxes of the forums?
Maybe something like this, a plugin using hook forumbit_display:
global $forum_counter;
$show['forumbit_ad'] = false;
if ($depth == 1)
$forum_counter = 0;
else if ($depth == 2)
$show['forumbit_ad'] = ($forum_counter++ % 4);
Then change your template condition to:
<vb:if condition="$show['forumbit_ad']">TEST</vb:if>
Forum-Germany
05-02-2014, 11:23 AM
Thank you for F your efforts! :)
Unfortunately, it does not yet work properly.
- Forum 1
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
- Forum 2
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums TEST
- Forum 3
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums TEST
-- Sub-Forums
-- Sub-Forums TEST
Oh right, I think it should have been:
global $forum_counter;
$show['forumbit_ad'] = false;
if ($depth == 1)
$forum_counter = 1;
else if ($depth == 2)
$show['forumbit_ad'] = !($forum_counter++ % 4);
Forum-Germany
05-02-2014, 09:55 PM
It works. :up: But not in the first forum.
- Forum 1
-- Sub-Forums TEST :confused:
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST
-- Sub-Forums
- Forum 2
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST :up:
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST :up:
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
- Forum 3
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums
-- Sub-Forums TEST :up:
-- Sub-Forums
-- Sub-Forums
Hmm...well, I guess I'm at the point where I'd have to try it myself. Maybe I'll get a chance tomorrow.
Forum-Germany
05-02-2014, 10:21 PM
I thank you from the heart! :up:
OK, try this:
global $forum_counter;
$show['forumbit_ad'] = false;
if ($depth == 1)
$forum_counter = 0;
else if ($depth == 2)
$show['forumbit_ad'] = !(++$forum_counter % 4);
it seems to work for me, but I think it depends on your exact forum structure.
Forum-Germany
05-03-2014, 01:59 PM
It works! You are the man! ;)
Could you still extend the code on the last forum? So that's the last forum is detected?
The last child? Maybe something like this:
global $forum_counter;
$show['forumbit_ad'] = false;
if ($depth == 1)
$forum_counter = 0;
else if ($depth == 2)
$show['forumbit_ad'] = !(++$forum_counter % 4);
$children = array_values($vbulletin->iforumcache["$parentid"]);
$show['last_child_forum'] = (end($children) == $forumid);
Then in the template
<vb:if condition="$show['last_child_forum']">LAST</vb:if>
Forum-Germany
05-03-2014, 03:55 PM
THANK YOU! :up: :up: :up:
--------------- Added 1399141625 at 1399141625 ---------------
A change I would need yet. Hoping for your support. :)
I would just need a condition that checks whether the last element is not the 4th item.
example:
A forum category has only 3 sub-forums.
Text "LAST" to be displayed only when the last element is not the fourth.
Forum-Germany
05-07-2014, 01:13 AM
Hello. :)
I think you have not read my last post (because of double post). :o
Can you tell me please still help with this one thing? :o
If the last element (sub-board) is not the 4th, it is also to be "marked".
Well, you have $show['forumbit_ad'] and $show['last_child_forum'], so you should be able to check both if you want. For example:
<vb:if condition="$show['last_child_forum'] AND !$show['forumbit_ad']">LAST</vb:if>
Forum-Germany
05-07-2014, 07:11 PM
THANK YOU! :up:
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.