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

Reply
 
Thread Tools
[HOW TO - vB4] Create a New Tab in the navbar
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 10-26-2009, 10:00 PM

Here's a pretty simple method for creating a new tab in the navbar, along with a submenu to go along with it. All you need is a unique condition for when your tab will be shown. What you will be making is a plugin to create the Nav Link along with a submenu which Link 1, Link 2, Link 3, and Drop Down which then drops down and has SubLink 1, SubLink 2, and SubLink 3. This is shown below.

NOTE: This is for 4.0.x and 4.1.x. In 4.2.x, you should be using the Navigation Manager.




This article is NOT to be used just to add another link to a submenu. It is for creating the Nav Link tab along with all the submenus. Again, if all you want is to add submenus to an existing tab, then this article is NOT for you!!!

This article is also for use by users who understand the basics of conditions and can write them. The navbar is not really an easy thing to play with if you don't know what you are doing - I think even Wayne said it had issues - so don't try this if you don't understand how to write a condition.

OK, with that out of the way....

Here's the basic template for making your new tab:

Create a plugin (Plugins & Products) > Add New Plugin:
hook location - process_templates_complete *
Title - New Tab for Navbar
Execution Order - 5
(* I used to have this listed as global_state_check but then noticed vb themselves use the process_templates_complete hook location, so I changed it.)

PHP Code:
$tabselected '';
$tablinks '';
if (
THIS_SCRIPT == 'yourpage')
{
    
$vbulletin->options['selectednavtab']='unique_name';
    
$tabselected ' class="selected"';
    
$tablinks '                <ul class="floatcontainer">
                        <li><a href="link1.php">Link 1</a></li>
                            <li class="popupmenu">
                                <a href="javascript://" class="popupctrl">Drop Down</a>
                                <ul class="popupbody popuphover">
                                        <li><a href="sublink1.php">SubLink 1</a></li>
                                        <li><a href="sublink2.php">SubLink 2</a></li>
                                        <li><a href="sublink3.php">SubLink 3</a></li>
                                </ul>
                            </li>
                        <li><a href="link2.php">Link 2</a></li>
                        <li><a href="link3.php">Link 3</a></li>
                </ul> '
;


$template_hook['navtab_end'] .= '<li'.$tabselected.'><a class="navtab" href="link.php">Nav Link</a>'.$tablinks.'</li>' 
Things to take note of:

PHP Code:
if (THIS_SCRIPT == 'yourpage'
Your condition MUST be unique! If you use a condition that is also going to evaluate to true for another tab, then they will both be highlighted and the wrong submenu may show up underneath.

PHP Code:
$vbulletin->options['selectednavtab']='unique_name'
The 'seletednavtab' must also be a unique name. Again, if you have two tabs with the same 'selectednavtab' name, then both tabs will be highlighted.

PHP Code:
$template_hook['navtab_end'] .= '<li'.$tabselected.'><a class="navtab" href="link.php">Nav Link</a>'.$tablinks.'</li>' 
You may use a different template_hook here - it just depends on where you want your tab to be - navtab_start and navtab_middle are also available.


ragtek also posted an article to do the same thing only using a template with the plugin - [HOW TO - vB4] Create a New Tab in the navbar (with template)



Originally posted on vb.org 2009-10-27.

Other related articles of possible interest:
[HOW TO - vB4] Remove the vB Default Navtabs
[HOW TO - vB4] Create your own vBulletin page
Attached Images
File Type: png vb4_nav_links.png (21.8 KB, 0 views)
Reply With Quote
  #192  
Old 03-01-2010, 03:22 PM
shooptek shooptek is offline
 
Join Date: Feb 2009
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there an easier way to do so or maybe a guide I could follow? I dont have much experience with vBulletin Conditionals.

Thanks
Reply With Quote
  #193  
Old 03-04-2010, 06:44 PM
Wilfred1 Wilfred1 is offline
 
Join Date: Jul 2009
Posts: 99
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is great however the only issue I have found is the height of the navbar isn't consistent.

Here is what I mean:
Attachment 113573

This is my plugin code:
Code:
$tabselected = '';
$tablinks = '';
if (THIS_SCRIPT == 'adv_index')
{
    $vbulletin->options['selectednavtab']='Home';
    $tabselected = ' class="selected"';
    $tablinks = '';

} 
$template_hook['navtab_start'] .= '<li'.$tabselected.'><a class="navtab" href="../index.php">Home</a>'.$tablinks.'</li>' ;

$tabselected = '';
$tablinks = '';
if (THIS_SCRIPT == 'online')
{
    $vbulletin->options['selectednavtab']='Online';
    $tabselected2 = ' class="selected"';
    $tablinks2 = '                <ul class="floatcontainer">
                        <li><a href="link1.php">Online</a></li>
                            <li class="popupmenu">
                                <a href="javascript://" class="popupctrl">Drop Down</a>
                                <ul class="popupbody popuphover">
                                        <li><a href="sublink1.php">SubLink 1</a></li>
                                        <li><a href="sublink2.php">SubLink 2</a></li>
                                        <li><a href="sublink3.php">SubLink 3</a></li>
                                </ul>
                            </li>
                        <li><a href="link2.php">Link 2</a></li>
                        <li><a href="link3.php">Link 3</a></li>
                </ul> ';

} 
$template_hook['navtab_end'] .= '<li'.$tabselected2.'><a class="navtab" href="../forum/online.php">Online</a>'.$tablinks2.'</li>' ;

$tabselected = '';
$tablinks = '';
if (THIS_SCRIPT == 'calendar')
{
    $vbulletin->options['selectednavtab']='Events';
    $tabselected3 = ' class="selected"';
    $tablinks3 = '                <ul class="floatcontainer">
                        <li><a href="link1.php">Events</a></li>
                            <li class="popupmenu">
                                <a href="javascript://" class="popupctrl">Drop Down</a>
                                <ul class="popupbody popuphover">
                                        <li><a href="sublink1.php">SubLink 1</a></li>
                                        <li><a href="sublink2.php">SubLink 2</a></li>
                                        <li><a href="sublink3.php">SubLink 3</a></li>
                                </ul>
                            </li>
                        <li><a href="link2.php">Link 2</a></li>
                        <li><a href="link3.php">Link 3</a></li>
                </ul> ';

} 
$template_hook['navtab_end'] .= '<li'.$tabselected3.'><a class="navtab" href="../forum/calendar.php">Events</a>'.$tablinks3.'</li>' ;
The other thing is the above code seems very inefficient to me - I will probably have another few more tabs as well so it would need to be stepping through a lot just to create the tabs and sub menus or in the scheme of things going through this code each time a page is displayed is not worth worring about - any thoughts?
Reply With Quote
  #194  
Old 03-04-2010, 11:05 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Wilfred1 View Post
This is great however the only issue I have found is the height of the navbar isn't consistent.

Here is what I mean:
Attachment 113573

The other thing is the above code seems very inefficient to me - I will probably have another few more tabs as well so it would need to be stepping through a lot just to create the tabs and sub menus or in the scheme of things going through this code each time a page is displayed is not worth worring about - any thoughts?
You will have to look at your code using something like firebug to see why it is doing what it is doing. I can't tell from the image.

As for it being inefficient, I wrote this just to add a single tab. I suppose it could be modified slightly to make it more efficient when you add several tabs, but I really don't know that it would make a huge impact.
Reply With Quote
  #195  
Old 03-04-2010, 11:20 PM
Wilfred1 Wilfred1 is offline
 
Join Date: Jul 2009
Posts: 99
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynn - have worked out that if you don't have a sub menu under a tab you will get that inconsistency in the navbar height so I have added a sub menu like "About", "Site Rules" etc and that fixed it.

Any suggestions on how I could make it more efficient so I can have tabs across the page - thanks!
Reply With Quote
  #196  
Old 03-06-2010, 04:12 PM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

unfortunately this just doesn't work for me. i added the plugin with the exact things you posted in your entry post (just to see, if it works) and it doesn't even generate a navtab, even though the plugin is activated. I'm on vB 4.0.2 PL1

EDIT: okay nvm. i had to enable the plugins globally.
Reply With Quote
  #197  
Old 03-09-2010, 06:35 AM
Theda Theda is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've got this working except for the selected tab being highlighted as "on". What I need now is to figure out how to specify each of these specific articles as the condition. I have added three tabs: Raid Teams, Roster and Recruitment.

Each of these tabs points to a specific article, meaning content.php?r=articlename.
How can I specify that as my condition? Since they are articles, I can't use the THIS SCRIPT since it's content.php?r=articlename?

I tried article titles (since that worked for my content section vb:if code, but it didn't work for this.... if ("$title == 'Raid Teams'")

Code:
$tabselected = '';
$tablinks = '';
if (THIS_SCRIPT == 'content.php?r=180-Raid-Teams')
{
    $vbulletin->options['selectednavtab']='Raid Teams';
    $tabselected = ' class="selected"';
} 
$template_hook['navtab_start'] .= '<li'.$tabselected.'><a class="navtab" href="content.php?r=180-Raid-Teams">Raid Teams</a>'.$tablinks.'</li>' ;
Reply With Quote
  #198  
Old 03-09-2010, 01:56 PM
Lord Zedd's Avatar
Lord Zedd Lord Zedd is offline
 
Join Date: Apr 2006
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello Lynne,

You have helped me out with a lot of problems on Vbulletin.com yesterday and today. I am hoping you can help me out with something here.

There are a couple of things I am not sure about. I did what you said in your first post. The Nav Link tab appeared. I changed it to Home and changed aswell the link. It worked perfectly. Thank you for that! You are helping out many people!

- Do I need to add the same plugin for each tab I need to create? Or do you edit it in the code?

- Is there a way to organize the tabs? I only got the forum installed and not the CMS. My first tab is Forum, than What's new and than the Nav Link (now renamed it to Home). When I edit the code and the new tab is hooked to navbar_start instead of navbar_end. Than it shows before Forum and What's new. That is good. But I need to create 4 more tabs. How can I organize those if they appear after navbar_end?
Reply With Quote
  #199  
Old 03-09-2010, 02:59 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Theda View Post
I've got this working except for the selected tab being highlighted as "on". What I need now is to figure out how to specify each of these specific articles as the condition. I have added three tabs: Raid Teams, Roster and Recruitment.

Each of these tabs points to a specific article, meaning content.php?r=articlename.
How can I specify that as my condition? Since they are articles, I can't use the THIS SCRIPT since it's content.php?r=articlename?

I tried article titles (since that worked for my content section vb:if code, but it didn't work for this.... if ("$title == 'Raid Teams'")
I *think* you can use the nodeid variable. Edwin has talked about it over on vb.com in relation to articles and sections. So, you may want to look into that. But, you will probably also have to dive into the code that decides when the Home page is the selected page in order to only select the Home page as selected when those $nodeids are not true.
Quote:
Originally Posted by Lord Zedd View Post

- Do I need to add the same plugin for each tab I need to create? Or do you edit it in the code?

- Is there a way to organize the tabs? I only got the forum installed and not the CMS. My first tab is Forum, than What's new and than the Nav Link (now renamed it to Home). When I edit the code and the new tab is hooked to navbar_start instead of navbar_end. Than it shows before Forum and What's new. That is good. But I need to create 4 more tabs. How can I organize those if they appear after navbar_end?
You can put all the tabs into one plugin. If they are all using the same $template_hook, then put them in the order you want them to appear. I think someone posted some code in the last couple pages showing their plugin for a couple of tabs.
Reply With Quote
  #200  
Old 03-10-2010, 07:31 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For the php condition in CMS you should be able to use
PHP Code:
if (in_array($this->content->getNodeId(), array(1,2,3))) 
for line 3 of Lynnes code, where 1,2,3 is a comma delimited list of the nodeids of the article/sections that you want to show your tab as highlighted on.

Now, if you have your custom tab highlighted, you don't want the Home Tab highlighted at the same time. To prevent Home Tab being selected, edit Template vbcms_navbar_link
Code:
<vb:if condition="$vboptions['selectednavtab'] == 'vbcms' AND !in_array($nodeid, array(1,2,3))">
Add the red code to the condition in the first line of the template and replace 1,2,3 with a comma delimited list of the nodeids that you don't want to show the Home-Tab selected.
Reply With Quote
  #201  
Old 03-10-2010, 01:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you, cellarius! I knew what had to be done, just not exactly how to do it. Thanks for posting that.
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 12:46 AM.


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.06120 seconds
  • Memory Usage 2,374KB
  • Queries Executed 26 (?)
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
  • (3)bbcode_code
  • (5)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (10)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete