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] Adding Navigation Tabs Fast and Easy
vbresults
Join Date: Apr 2009
Posts: 687

 

Show Printable Version Email this Page Subscription
vbresults vbresults is offline 10-09-2011, 10:00 PM

Spoiler (vBulletin 4):



PHP Code:
// Yes, this is all the code you need to add the example above.

ExtendedNavigations::update(array(
    
'name' => 'Test Tab',
    
'children' => array(
        
'URL_1' => 'Sub Link 1',
        
'URL_2' => 'Sub Link 1.1',
        
'URL_3' => 'Sub Link 1.1.1'
    
),
    
'top_level' => true // NEW FEATURE IN 1.5
)); 
Spoiler (vBulletin 3):



PHP Code:
ExtendedNavigations::update(array(
    
'name' => 'Test Tab',
    
'children' => array(
        
'Link A' => array(
            
'URL_1' => 'Sub Link 1',
            
'URL_2' => 'Sub Link 1.1',
            
'URL_3' => 'Sub Link 1.1.1'
        
)
    )
)); 
---

Adding a navigation tab is not a new concept. There are two articles (Lynne's and Ragtek's) on vBulletin.org showing how to do this. Both solutions work, but you are reading this to learn how to do take it from workable to fast, efficient, and portable.

Let's first explore the two ways it is currently done. Let's say we want to add a 'Twitter' tab, linking to "twitter.com/xyz", on every page.

Using Lynne's method:
Plugin (hook: process_templates_complete)
PHP Code:
$template_hook['navtab_end'] .= '<li><a class="navtab" href="http://twitter.com/xyz">Twitter</a></li>' 
The benefit to this method is that it is straightforward for static, childless tabs; if you know a little php and html, this is not too difficult to implement. The problem with this method is that everything is hard-coded. The html is static; it does not make use of the template or phrase system. If you want to change the tab and add sub-links and drop-downs, you have mess with the html to get it just right. Doing anything else is going to require advanced skills and knowledge of the navigation tab system (first article), no matter how you slice it.

Using Ragtek's method:
HTML Code:
<!-- New Template: ragtek_twitter_navbar -->

<li><a class="navtab" href="http://twitter.com/xyz">{vb:rawphrase twitter}</a></li>
Plugin (hook: process_templates_complete)
PHP Code:
$template_hook['navtab_middle'] .= vB_Template::create('ragtek_twitter_navbar')->render(); 
This method addresses on some of the weaknesses of Lynne's method and inherits others. Benefits include making use of the phrase and template systems. On the other hand, this shares many of the same weaknesses on the plugin side; anything but the most simple tab is going to require advanced knowledge (second article).



The first two choices come down to either simplicity at the cost of flexibility, or flexibility at the cost of complexity. There is a way to have the best of both worlds and the worst of none.

How? The answer lies in the `LancerForHire - Extended Navigations` product.

Enter, `ExtendedNavigations::update`:
PHP Code:
ExtendedNavigations::update(array('name' => $vbphrase['twitter'], 'url' => 'http://twitter.com/xyz')); 
Let's bring this into context by replicating the tab examples in the two articles, but using the ExtendedNavigations class.

Lynne's:
Plugin (hook: global_setup_complete), Order: 999 or less
PHP Code:
ExtendedNavigations::update(
    array(
        
'name' => 'Link 1',
        
'script' => 'yourpage',
        
'children' => array(
            
'Drop Down' => array(
                
'sublink1.php' => 'SubLink 1',
                
'sublink2.php' => 'SubLink 2',
                
'sublink3.php' => 'SubLink 3'
            
)
        )
    ),
    array(
        
'name' => 'Link 2',
        
'url' => 'link2.php'
    
),
    array(
        
'name' => 'Link 3',
        
'url' => 'link3.php'
    
)
); 
Ragtek's:
Plugin (hook: global_setup_complete), Order: 999 or less
PHP Code:
ExtendedNavigations::update(
    array(
        
'name' => $vbphrase['ragtek_news'],
        
'script' => 'ragteknews',
        
'url' => 'news.php',
        
'children' => array(
            
'#' => '#'
        
)
    )
); 
No static html, no css classes, no new templates, no conditions. Simple. You could even drop this code in vB 3 and have a new navigation link (more in the final section).

The `ExtendedNavigations::update` function takes a variable number of arrays. Each array ($options) follows the format below.
Quote:
$options['name']

Data Type: string. Required.

This is the name of the primary tab.

$options['url']

Data Type: string. Optional if $options['script'] is set; required otherwise.

This is the url of the primary tab.

$options['top_level'] (New in 1.5!)

Data Type: boolean. Optional. Default: false. This option is always/forcefully enabled in vBulletin 3.

Whether or not to use the direct menu format. See $options['children'] for more information.

$options['script']

Data Type: string. Optional if $options['url'] is set; required otherwise. This option has no effect in vBulletin 3.

This is the script that will highlight the primary tab, making the children/secondary links visible. If $options['url'] is empty, $options['url'] will be set to "{$options['script']}.php".

$options['after']

Data Type: boolean. Optional. Default: true.

Whether or not to show the primary tab after the default tabs. If set to false, the primary tab will show before the default ones.

$options['children']

Data Type: array. Optional.

The links or menus contained by the primary tab. Each array element can follow the following format:

PHP Code:
string 'Child Link Name' => string 'Child Link Url' 
If $options['top_level'] is enabled, the primary tab will become a drop-down in vBulletin 4. This format is not understood by vBulletin 3.

or

PHP Code:
string 'Drop-down Name' => array(
    
'Drop-down Item-1 Link' => 'Drop-down Item-1 Name',
    
'Drop-down Item-2 Link' => 'Drop-down Item-2 Name'
    
# and so on...
); 
This is not supported in vBulletin 4 if $options['top_level'] is enabled. In vBulletin 3, this is the standard format.
How do I get this?

Download the product-extended_navigations_ Xml and add it (extended_navigations) as a product dependency. Yes; that's it!

Extended Navigations is reverse compatible and can be used to add tabs to vBulletin 3 easily. To use Extended Navigations in vBulletin 3, an additional product download and dependency are required: product-extended_legacies. No code changes required.

Brought to you by LancerForHire, LLC.
Attached Images
File Type: png extended_navigations_15_top_level.png (6.9 KB, 0 views)
File Type: png extended_navigations_15_legacy.png (20.7 KB, 0 views)
Attached Files
File Type: xml product-extended_legacies-1.3.1.xml (3.6 KB, 24 views)
File Type: xml product-extended_navigations-1.5.xml (6.9 KB, 50 views)
Reply With Quote
  #12  
Old 10-30-2011, 12:55 PM
fluidswork's Avatar
fluidswork fluidswork is offline
 
Join Date: Apr 2010
Location: India
Posts: 143
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great ..............
Reply With Quote
  #13  
Old 11-08-2011, 08:00 AM
abdobasha2004's Avatar
abdobasha2004 abdobasha2004 is offline
 
Join Date: Aug 2008
Posts: 541
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks for sharing this
.....
Reply With Quote
  #14  
Old 03-23-2012, 05:54 AM
vbresults vbresults is offline
 
Join Date: Apr 2009
Posts: 687
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Updated OP.
Reply With Quote
  #15  
Old 05-03-2012, 06:53 PM
vbresults vbresults is offline
 
Join Date: Apr 2009
Posts: 687
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Massive changes in 1.5!
  1. Added $options['top_level'] feature (direct menus).
  2. vBulletin 3 Drop-Down Menu Support
  3. $options['children'] value (url)/key (name) order changed to the proper order, key/value.

#1 means the functionality sweetpotato was talking about is now included.
Reply With Quote
  #16  
Old 05-14-2012, 07:16 AM
Winter Sonata Winter Sonata is offline
 
Join Date: Apr 2010
Posts: 232
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How can I make the custom tab placed before the Forum tab?
Reply With Quote
  #17  
Old 05-22-2012, 03:16 PM
vbresults vbresults is offline
 
Join Date: Apr 2009
Posts: 687
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Winter Sonata View Post
How can I make the custom tab placed before the Forum tab?
Set $options['after'] to false
Reply With Quote
  #18  
Old 01-10-2013, 04:45 PM
Nocturnal222 Nocturnal222 is offline
 
Join Date: Dec 2006
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I will just upload this and edit the texts on vbulletin options?
Reply With Quote
  #19  
Old 07-27-2013, 01:57 PM
ahobilam's Avatar
ahobilam ahobilam is offline
 
Join Date: Aug 2011
Location: Chennai, India
Posts: 128
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you explain how to create a tab - drop down menu -> popup menu from drop down menu item like below?
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 10:20 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.08105 seconds
  • Memory Usage 2,355KB
  • Queries Executed 24 (?)
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)bbcode_html
  • (9)bbcode_php
  • (2)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
  • (1)pagenav_pagelink
  • (9)post_thanks_box
  • (8)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (8)postbit
  • (4)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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