Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
How To Highlight Current Item in a CSS Menu?
aveon's Avatar
aveon
Join Date: May 2006
Posts: 410

 

Show Printable Version Email this Page Subscription
aveon aveon is offline 06-24-2007, 10:00 PM

Hello everyone!

This tutorial will show you how to highlight the current link on a css menu.

ok lets make a quick simple css menu...

CSS Starts
Code:
#navcontainer
{
margin-bottom: 1em;
overflow: hidden;
width: 460px;
}

#navlist
{
list-style-type: none;
margin: 0;
padding: 0;
}

#navlist li
{
border-left: 1px solid #000;
float: left;
line-height: 1.1em;
margin: 0 .5em 0 -.5em;
padding: 0 .5em 0 .5em;
}

#navlist li a:hover,#navlist a#active
{
border-left: 1px solid red;
text-decoration: underline;
float: left;
line-height: 1.1em;
margin: 0 .5em 0 -.5em;
padding: 0 .5em 0 .5em;
}
Done With Css Menu...

Now Lets Create Our Html Menu...

HTML Code:
<div id="navcontainer">
<ul id="navlist">
<li><a href="index.php">Main Page</a></li>
<li><a href="usercp.php">UserCP</a></li>
<li><a href="search.php">Search</a></li>
<li><a href="calendar.php">Calendar</a></li>
<li><a href="forumdisplay.php?f=1">Announcements</a></li>
</ul>
</div>
Done With The HTML Menu.....

Now there are not many ways on vb to get the current link highlighted but we have if conditionals which will help us in this situation so first of all lets see the conditionals which will be helpful for us...

#1 Links Using the .php pages (#ex. search.php, index.php)

for .php pages every php page has a definition somewhere at the top of the .php file and that string goes like
Code:
define('THIS_SCRIPT', 'xxx');
the definition is located where the xxx is... and at this point the if conditional going to be

Code:
<if condition="THIS_SCRIPT=='xxx'">
**if you have more than one .php files which u want to use on your menu your conditional string will go like
Code:
<if condition="in_array(THIS_SCRIPT, array(xxx, xxx, xxx))">
**

we are done for this point...

#2 Highlighting Forumdisplay Pages (#ex. forumdisplay.php?f=1)

this is going to be difficult for beginners because if you have a planny of forums in one category and u want the link to be highlighted for each of them it will take us some time to go over everyone of it but don't worry it is easy after you start... so here we go...

we will be using an if conditional for this one ass well... Our conditional will be
Code:
<if condition="in_array($foruminfo['forumid'], array(x, x, x, x, x))">
...

to apply this code in our menu we have to see the forum id's we can check them either in admincp or in forum itself.. ones u get the forumid's selected for our menu lets put them in our conditional...

main category id>> 1
sub categories>> 2, 3, 4, 5

Code:
<if condition="in_array($foruminfo['forumid'], array(1, 2, 3, 4, 5))">
this part is done ass well..

#3. How To Combine 2 Conditional Together...

if you want to use a .php file and a forumdisplay page for your menu you need to combine the two conditional together and it will going to look like;

Code:
<if condition="in_array(THIS_SCRIPT, array(xxx, xxx, xxx, xxx)) OR in_array($foruminfo['forumid'], array(x, x, x, x, x))">
and it is simple as that..

Now Lets Apply Our Conditional To Our CSS Menu;

Our Html Menu Was

HTML Code:
<div id="navcontainer">
<ul id="navlist">
<li><a href="index.php">Main Page</a></li>
<li><a href="usercp.php">UserCP</a></li>
<li><a href="search.php">Search</a></li>
<li><a href="calendar.php">Calendar</a></li>
<li><a href="forumdisplay.php?f=1">Announcements</a></li>
</ul>
</div>
**Now Lets Begin**

first link is
HTML Code:
<li><a href="index.php">Main Page</a></li>
so lets apply the conditional...

our .php definition is 'index' so our if conditional will look like
HTML Code:
<if condition="THIS_SCRIPT=='index'">
and our menu going to be like

HTML Code:
<if condition="THIS_SCRIPT=='index'"><li id="active"><a href="index.php" id="active">Main Page</a></li><else /><li><a href="index.php">Main Page</a></li>
lets apply this on evey link which is using .php page...

HTML Code:
<if condition="in_array(THIS_SCRIPT, array(usercp, profile, private, moderation))"><li id="active"><a href="usercp.php" id="active">UserCP</a></li><else /><li><a href="usercp.php">UserCP</a></li></if>

<if condition="THIS_SCRIPT=='search'"><li id="active"><a href="search.php" id="active">Search</a></li><else /><li><a href="search.php">Search</a></li></if>

<if condition="THIS_SCRIPT=='calendar'"><li id="active"><a href="calendar.php" id="active">Calendar</a></li><else /><li><a href="calendar.php">Calendar</a></li>/if>
Our Last Item was
HTML Code:
<li><a href="forumdisplay.php?f=1">Announcements</a></li>
.. So lets begin applying our conditional on our link...

we will be using
HTML Code:
[code]<if condition="in_array($foruminfo['forumid'], array(1, 2, 3, 4, 5))">[/code]
and our menu is going to be

HTML Code:
<if condition="in_array($foruminfo['forumid'], array(1, 2, 3, 4, 5))"><li id="active"><a href="forumdisplay.php?f=1" id="active">Announcements</a></li><else /><li><a href="forumdisplay.php?f=1">Announcements</a></li></if>
So Finally We Are Done!!

here is our html menu!

HTML Code:
<if condition="THIS_SCRIPT=='index'"><li id="active"><a href="index.php" id="active">Main Page</a></li><else /><li><a href="index.php">Main Page</a></li>

<if condition="in_array(THIS_SCRIPT, array(usercp, profile, private, moderation))"><li id="active"><a href="usercp.php" id="active">UserCP</a></li><else /><li><a href="usercp.php">UserCP</a></li></if>

<if condition="THIS_SCRIPT=='search'"><li id="active"><a href="search.php" id="active">Search</a></li><else /><li><a href="search.php">Search</a></li></if>

<if condition="THIS_SCRIPT=='calendar'"><li id="active"><a href="calendar.php" id="active">Calendar</a></li><else /><li><a href="calendar.php">Calendar</a></li>/if>

<if condition="in_array($foruminfo['forumid'], array(1, 2, 3, 4, 5))"><li id="active"><a href="forumdisplay.php?f=1" id="active">Announcements</a></li><else /><li><a href="forumdisplay.php?f=1">Announcements</a></li></if>
I Hope U Enjoyed it...

aveon...
Reply With Quote
  #2  
Old 06-25-2007, 11:21 PM
Alfa1's Avatar
Alfa1 Alfa1 is offline
 
Join Date: Dec 2005
Location: Netherlands
Posts: 3,537
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To save some of you from carpal tunnel syndrome, here is a range of forumID's you can copy paste:

array(1 , 2, 3, 4 ,5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190))
Reply With Quote
  #3  
Old 09-25-2007, 12:34 PM
ReQueM ReQueM is offline
 
Join Date: Dec 2006
Location: Turkey
Posts: 98
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank u aveon :up:
Reply With Quote
  #4  
Old 10-17-2007, 01:56 PM
KoC KoC is offline
 
Join Date: May 2005
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very important post. Thank you...
Reply With Quote
  #5  
Old 01-10-2008, 10:46 PM
blastup blastup is offline
 
Join Date: Feb 2007
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

that is freaken awesome thanks for this useful post..i used it and works great on my forum.. great tutorial .. a recommendation to all the people use the <else /> condition. if you say like you want the rest of the forum to display something use the <else />.so you do not have to define using individual ids .. it is just everything else.. alright peace out - if you need help let me know i own a webmasters forum at http://millionwebmasters.com
Reply With Quote
  #6  
Old 05-24-2008, 05:17 PM
unleash unleash is offline
 
Join Date: Jan 2006
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks alot, this was very very helpful, i was looking for this
Reply With Quote
  #7  
Old 02-20-2009, 10:49 AM
career career is offline
 
Join Date: Feb 2009
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Aveon!
Reply With Quote
  #8  
Old 04-07-2009, 02:32 PM
NetRover NetRover is offline
 
Join Date: Jul 2004
Posts: 123
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome, thank you so much for this advice. I've manage nice active tabbed forums with subforums.

good stuff.
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 06:50 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.05023 seconds
  • Memory Usage 2,301KB
  • Queries Executed 23 (?)
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
  • (7)bbcode_code
  • (10)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)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
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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