vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Need a Condition (https://vborg.vbsupport.ru/showthread.php?t=310957)

Forum-Germany 05-01-2014 07:56 PM

Need a Condition
 
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?

Code:

<vb:if condition="$GLOBALS[counter]++"></vb:if>

kh99 05-01-2014 08:06 PM

You could try this:
Code:

<vb:if condition="($GLOBALS[counter]++ % 4) == 0"></vb:if>

Forum-Germany 05-01-2014 08:13 PM

Thanks!

My Forum with your Code.

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

kh99 05-01-2014 08:44 PM

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?

kh99 05-01-2014 09:01 PM

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:

Quote:

- 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.

Quote:

- 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?

kh99 05-02-2014 08:36 AM

Maybe something like this, a plugin using hook forumbit_display:
PHP Code:

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:
Code:

<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

kh99 05-02-2014 06:49 PM

Oh right, I think it should have been:
PHP Code:

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

kh99 05-02-2014 10:01 PM

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:

kh99 05-03-2014 11:39 AM

OK, try this:
PHP Code:

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?

kh99 05-03-2014 03:29 PM

The last child? Maybe something like this:
PHP Code:

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
Code:

<vb:if condition="$show['last_child_forum']">LAST</vb:if>

Forum-Germany 05-03-2014 03:55 PM

THANK YOU! :up: :up: :up:

--------------- Added [DATE]1399141625[/DATE] at [TIME]1399141625[/TIME] ---------------

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".

kh99 05-07-2014 07:44 AM

Well, you have $show['forumbit_ad'] and $show['last_child_forum'], so you should be able to check both if you want. For example:
Code:

<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:


All times are GMT. The time now is 07:19 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01294 seconds
  • Memory Usage 1,783KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (24)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete