Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Design and Graphics Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2021, 09:50 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [General Development] Highlighting active page in a navbar?

When it comes to highlighting the active page in a navbar I find myself using if conditions, just what I've grown accustomed to.

Example: (may not be perfect, just going from the top of my head)
HTML Code:
<a href="" class="class<if condition="(THIS_SCRIPT=='index')"> active</if>">Home</a>
<a href="" class="class<if condition="($_REQUEST['do']=='page')"> active</if>">Page</a>
<a href="" class="class<if condition="in_array(THIS_SCRIPT, array(showthread,forumdisplay))"> active</if>">Threads</a>
<a href="" class="class<if condition="($_REQUEST['do']!='AD')"> active</if>">Highlight if not active</a>
I was wondering to avoid the multiple if's, is their an easier way (or better way) for achieving this concept?

I'm asking here rather than on stack because we are vBulletin users, and a lot of stack members tend to have issues with vb lol, and maybe vb has a whole different way of detecting the current page.
Reply With Quote
  #2  
Old 02-19-2021, 02:57 PM
yilmaz's Avatar
yilmaz yilmaz is offline
 
Join Date: Sep 2004
Posts: 751
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change
PHP Code:
<if condition="(THIS_SCRIPT=='index')"active</if>">Home</a> 
To
PHP Code:
<vb:if condition="(THIS_SCRIPT=='index')"active</vb:if>">Home</a> 
Reply With Quote
  #3  
Old 02-19-2021, 03:52 PM
puertoblack2003's Avatar
puertoblack2003 puertoblack2003 is offline
 
Join Date: Aug 2005
Location: Philadelphia
Posts: 1,073
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by yilmaz View Post
Change
PHP Code:
<if condition="(THIS_SCRIPT=='index')"active</if>">Home</a> 
To
PHP Code:
<vb:if condition="(THIS_SCRIPT=='index')"active</vb:if>">Home</a> 
isn't that vb 4 vb statement ?
Reply With Quote
  #4  
Old 02-19-2021, 03:57 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by yilmaz View Post
Change
PHP Code:
<if condition="(THIS_SCRIPT=='index')"active</if>">Home</a> 
To
PHP Code:
<vb:if condition="(THIS_SCRIPT=='index')"active</vb:if>">Home</a> 
no no no lol, I'm sorry if I wasn't clear its not about vb3 or vb4. It's about coding in general. I'm wondering if there is a better approach to detecting which page I am on, rather than having to use an if condition for each link.

I got to thinking a jQuery solution, I may add classes based on links. It would look something like:
Code:
$(".navLink a[href*='" + location.pathname + "']").addClass("active");
Which I'm thinking will be way better than a bunch of if conditions. it would turn that top piece of code into:
HTML Code:
<div class="navLink">
<a href="index.php" class="active">Home</a>  //We are on index so jQuery added class="active"
<a href="page.php">Page</a>
<a href="showthread.php">Threads</a>
</div>
Which is much easier to work with rather than having a bunch of ifs
as for the link we want styled if its not the current page, add its own class to it, and tell jQuery to remove it if it is the current page.
Reply With Quote
  #5  
Old 02-19-2021, 06:06 PM
yilmaz's Avatar
yilmaz yilmaz is offline
 
Join Date: Sep 2004
Posts: 751
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by puertoblack2003 View Post
isn't that vb 4 vb statement ?
Sorry, I replied as the topic is in the vb4 section.
Reply With Quote
  #6  
Old 02-19-2021, 06:14 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It was more a coding in general type of question, maybe should have posted in private coders, but i feel this section gets the most viewers lol.

It's something that could be applied too ANY vb version though.
Reply With Quote
  #7  
Old 02-19-2021, 06:33 PM
yilmaz's Avatar
yilmaz yilmaz is offline
 
Join Date: Sep 2004
Posts: 751
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
HTML Code:
<a href="" class="class<if condition="(THIS_SCRIPT=='index')"> active</if>">Home</a>
<a href="" class="class<if condition="($_REQUEST['do']=='page')"> active</if>">Page</a>
<a href="" class="class<if condition="in_array(THIS_SCRIPT, array(showthread,forumdisplay))"> active</if>">Threads</a>
<a href="" class="class<if condition="($_REQUEST['do']!='AD')"> active</if>">Highlight if not active</a>
This is the most logical.

Note: Maybe you know, you should always specify the name of that file first in the custom php page.
custom.php
PHP Code:
<?php
define
('THIS_SCRIPT''custom');
Reply With Quote
  #8  
Old 02-19-2021, 06:36 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so using if conditions is the way you would do? It just felt like too much, and I got to thinking of alternative ways lol
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:37 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08342 seconds
  • Memory Usage 2,254KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_html
  • (7)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete