Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

Reply
 
Thread Tools
[HOW TO - vB4] Create a New Tab in the navbar (with template)
ragtek
Join Date: Mar 2006
Posts: 1,630

 

austria, croatia
Show Printable Version Email this Page Subscription
ragtek ragtek is offline 11-17-2009, 10:00 PM

I know that lynne allready postet an article, but here's a other way:

This tutorial will show you, how to add own links to your navbar.
(In the tutorial i'll use the code for my news add-on)


1. create a template (ragtek_news_navbar)
HTML Code:
<vb:if condition="$vboptions['selectednavtab'] == 'ragteknews'">
<li class="selected">
    <a class="navtab" href="news.php{vb:raw session.sessionurl_q}">{vb:rawphrase ragtek_news}</a>
<ul class="floatcontainer">
<li><a href="#">#</a></li>
</ul>
</li>
<vb:else />
<li><a class="navtab" href="news.php{vb:raw session.sessionurl_q}">{vb:rawphrase ragtek_news}</a></li>
</vb:if>
2. Create a plugin at the hook process_templates_complete
PHP Code:
if (THIS_SCRIPT == 'xxx')  // also defined('ragteknews') possible
{
//set selected tab
    
$vbulletin->options['selectednavtab'] = 'ragteknews';
}
// add the "subtemplate" to the navbartemplate
$template_hook['navtab_middle'] .= vB_Template::create('ragtek_news_navbar')->render(); 
As you see, i've defined "ragteknews" on my news.php page.If ragteknews is defined, $vbulletion->options['selectednavtab'] will be set to ragteknews.
Thats important because where using a condition in the template:
HTML Code:
<vb:if condition="$vboptions['selectednavtab'] == 'ragteknews'">
Attached Images
File Type: png Forums_1258596385528.png (7.9 KB, 0 views)
File Type: png Forums - News_1258596373538.png (11.1 KB, 0 views)
Reply With Quote
  #62  
Old 01-21-2010, 09:22 PM
gabrielt gabrielt is offline
 
Join Date: Apr 2007
Posts: 89
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

Adapted this to create a link to my main website:

Plugin "Main Website Button", on process_template_complete:

Code:
$template_hook['navtab_middle'] .= vB_Template::create('Link to Main Website')->render();
Template "Link to Main Website":

Code:
<vb:if condition="$vboptions['selectednavtab'] == 'mainwebsite'">
<li class="selected">
<a class="navtab" href="{vb:raw vboptions.homeurl}">{vb:raw vboptions.hometitle}</a>
<ul class="floatcontainer">
<li><a href="#">#</a></li>
</ul>
</li>
<vb:else />
<li><a class="navtab" href="{vb:raw vboptions.homeurl}">{vb:raw vboptions.hometitle}</a></li>
</vb:if>
Enjoy!
Reply With Quote
  #63  
Old 01-27-2010, 06:28 PM
nsilva nsilva is offline
 
Join Date: Apr 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How come when I click on the nav tab, it shows the Forum tab as selected and not the tab I created?
Reply With Quote
  #64  
Old 01-27-2010, 06:44 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 nsilva View Post
How come when I click on the nav tab, it shows the Forum tab as selected and not the tab I created?
Because you didn't make the condition a valid condition for your tab.
Reply With Quote
  #65  
Old 03-10-2010, 07:03 AM
Chickenpotpie Chickenpotpie is offline
 
Join Date: Feb 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good article. It worked well. question. if I need to add more tabs do I need to make new templates and hooks?

-CP
Reply With Quote
  #66  
Old 03-19-2010, 04:57 PM
Sarcoth Sarcoth is offline
 
Join Date: Mar 2006
Location: Huntsville
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In case anyone is curious and you know how to create a permission group, here is how you can use that group to determine who can see the tab.

FIRST:
At the top of the plugin, add a variable for your permission group array:
PHP Code:
$accessgroups explode(','$vbulletin->options['permission_group_name']); 
SECOND:
At the bottom of the plugin, find the following line:
PHP Code:
$template_hook['navtab_end'] .= vB_Template::create('template_navbar')->render(); 
Change it to:
PHP Code:
$templater vB_Template::create('template_navbar');
    
$templater->register('accessgroups'$accessgroups);
$template_hook['navtab_end'] .= $templater->render(); 
THIRD:
Open your template and add a line to the top and the bottom.
HTML Code:
<vb:if condition="is_member_of($bbuserinfo, $accessgroups)">
HTML Code:
</vb:if>
NOTE: I know you could just edit the current if condition with an AND, but I think that will just confuse some people.
Reply With Quote
  #67  
Old 03-21-2010, 05:29 AM
Theda Theda is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I kind of modified this to try and use it with articles as "pages" with the tabs linked to articles.. (and it works, the tabs show as on).... but the HOME button is on too. Is there a way to set the home button to unselected?

Code:
$tabselected = '';
$tablinks = '';
if ($_GET ['r'] == '180-Roster')
{
    $vbulletin->options['selectednavtab']='Roster';
    $tabselected = ' class="selected"';
} 
$template_hook['navtab_start'] .= '<li'.$tabselected.'><a class="navtab" href="content.php?r=180-Roster">ROSTER</a>'.$tablinks.'</li>' ;
Reply With Quote
  #68  
Old 03-24-2010, 12:47 PM
Sarcoth Sarcoth is offline
 
Join Date: Mar 2006
Location: Huntsville
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I finally figured out a way to add all my variables from my custom page to the navbar. I went about it in a sneaky way.

I first added the following code to my showroster.php file which allowed me to add all the registered variables I wanted to use:

PHP Code:
$accessgroups explode(','$vbulletin->options['showroster_access_groups']);
$navbarloc $vbulletin->options['showroster_navbar_loc'];

switch (
$navbarloc) {
    case 
'1':
        
$nbloc 'navtab_start'; break;
    case 
'2':
        
$nbloc 'navtab_middle'; break;
    case 
'3':
        
$nbloc 'navtab_end'; break;
}

if (
THIS_SCRIPT == 'showroster') {
    
$vbulletin->options['selectednavtab'] = 'showroster'
}

$templater vB_Template::create('showroster_navbar');
    
$templater->register('sorturl'$sorturl);
    
$templater->register('accessgroups'$accessgroups);
    
$templater->register('columns'$columns);
    
$templater->register('sortgroupfield'$sortgroupfield);
    
$templater->register('oppositesort'$oppositesort);
$template_hook[$nbloc] .= $templater->render(); 
Since that was a close repeat to the code in my plugin, I ended up having one Roster button when on another tab and two when viewing the roster. I tried to remove the plugin, but that then caused the button to be missing when on another page; although it was there when on the roster. It makes sense after the fact. So, after some thought, I changed my plugin to the following:

PHP Code:
if (THIS_SCRIPT != 'showroster') {
$accessgroups explode(','$vbulletin->options['showroster_access_groups']);
$navbarloc $vbulletin->options['showroster_navbar_loc'];
$navbarorder $vbulletin->options['showroster_navbar_order']; 

switch (
$navbarloc) {
    case 
'1':
        
$nbloc 'navtab_start'; break;
    case 
'2':
        
$nbloc 'navtab_middle'; break;
    case 
'3':
        
$nbloc 'navtab_end'; break;
}

$templater vB_Template::create('showroster_navbar');
    
$templater->register('accessgroups'$accessgroups);
$template_hook[$nbloc] .= $templater->render();

That allowed me to use the plugin code when not on the roster page. When on the roster page, this code doesn't work, but the code from my showroster.php does. I then set up my showroster_navbar template to include the variables from my .php file and they work very well.

HTML Code:
<vb:if condition="is_member_of($bbuserinfo, $accessgroups)">
<vb:if condition="$vboptions['selectednavtab'] == 'showroster'">
<li class="selected">
	<a class="navtab" href="showroster.php{vb:raw session.sessionurl_q}">Roster</a>
	<ul class="floatcontainer">
		<li><a href="showroster.php{vb:raw session.sessionurl_q}">Default Sort</a></li>
		<li class="popupmenu">
			<a href="javascript://" class="popupctrl">Sorting Options</a>
			<ul class="popupbody popuphover">
				<vb:if condition="$show[field1st]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column1]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts1}</vb:if>&amp;sortgroupfield={vb:raw columns.column1}">{vb:raw columns.title1}</a></li></vb:if>
				<vb:if condition="$show[field2nd]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column2]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts2}</vb:if>&amp;sortgroupfield={vb:raw columns.column2}">{vb:raw columns.title2}</a></li></vb:if>
				<vb:if condition="$show[field3rd]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column3]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts3}</vb:if>&amp;sortgroupfield={vb:raw columns.column3}">{vb:raw columns.title3}</a></li></vb:if>
				<vb:if condition="$show[field4th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column4]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts4}</vb:if>&amp;sortgroupfield={vb:raw columns.column4}">{vb:raw columns.title4}</a></li></vb:if>
				<vb:if condition="$show[field5th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column5]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts5}</vb:if>&amp;sortgroupfield={vb:raw columns.column5}">{vb:raw columns.title5}</a></li></vb:if>
				<vb:if condition="$show[field6th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column6]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts6}</vb:if>&amp;sortgroupfield={vb:raw columns.column6}">{vb:raw columns.title6}</a></li></vb:if>
				<vb:if condition="$show[field7th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column7]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts7}</vb:if>&amp;sortgroupfield={vb:raw columns.column7}">{vb:raw columns.title7}</a></li></vb:if>
				<vb:if condition="$show[field8th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column8]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts8}</vb:if>&amp;sortgroupfield={vb:raw columns.column8}">{vb:raw columns.title8}</a></li></vb:if>
				<vb:if condition="$show[datejoinedcol]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == 'joindate'">{vb:raw oppositesort}<vb:else />{vb:raw columns.sortsdj}</vb:if>&amp;sortgroupfield=joindate">{vb:rawphrase join_date}</a></li></vb:if>
				<vb:if condition="$show[lastactivecol]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == 'lastactive'">{vb:raw oppositesort}<vb:else />{vb:raw columns.sortsla}</vb:if>&amp;sortgroupfield=lastactive">{vb:rawphrase last_activity}</a></li></vb:if>
			</ul>
		</li>
	</ul>
</li>
<vb:else />
<li><a class="navtab" href="showroster.php{vb:raw session.sessionurl_q}">Roster</a></li>
</vb:if>
</vb:if>
I'm not saying this is the best way, far from it. I would much rather have had a way to pull the data from my .php to the plugin and then use it in the template that way, but this works for now. I'll gladly accept a better way if someone can tell me. I'm sure I'm added more code than I need.
Reply With Quote
  #69  
Old 03-25-2010, 03:03 PM
shooptek shooptek is offline
 
Join Date: Feb 2009
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay I am struggling with this. I want to add a button on my navbar that links to a specific forum, and when a user is viewing that forum for the tab on the navbar to be highlighted.

So this is the information that I used:

template name: bb_navbar_events

template code:
HTML Code:
<vb:if condition="$vboptions['selectednavtab'] == 'navbarevents'">
<li class="selected">
    <a class="navtab" href="forumdisplay.php?8-Events{vb:raw session.sessionurl_q}">{vb:rawphrase navbar_events}</a>
<ul class="floatcontainer">
<li><a href="#">#</a></li>
</ul>
</li>
<vb:else />
<li><a class="navtab" href="forumdisplay.php?8-Events{vb:raw session.sessionurl_q}">{vb:rawphrase navbar_events}</a></li>
</vb:if>

plugin code:
PHP Code:
if (THIS_SCRIPT == 'xxx')  // also defined('navbarevents') possible
{
//set selected tab
    
$vbulletin->options['selectednavtab'] = 'navbarevents';
}
// add the "subtemplate" to the navbartemplate
$template_hook['navtab_middle'] .= vB_Template::create('bb_navbar_events')->render(); 

Should this arrangement be working properly?

I want the Events tab to be highlighted when it is on that page, but the Forum tab remains highlighted.

Any suggestions?
Reply With Quote
  #70  
Old 04-05-2010, 06:26 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How do you do PERMISSIONS with this? I use the following code for permissions in my mods, and it works fine...

Code:
if (!($permissions['medialibperms'] & $vbulletin->bf_ugp_medialibperms['cansubm']))
{
	print_no_permission();
}

I am trying to use this code in my plugin, but the permission ALWAYS fails...
Code:
if (THIS_SCRIPT == 'media')
{
	$vbulletin->options['selectednavtab'] = 'media';

	$categories = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "media_category");
	$submitperm = $permissions['medialibperms'] & $vbulletin->bf_ugp_medialibperms['cansubm'];

	while ($category = $vbulletin->db->fetch_array($categories))
	{
		$templater = vB_Template::create('media_NAVTAB_cat');
		$templater->register('categoryID', $category['categoryID']);
		$templater->register('catName', $category['catName']);
		$categorybits .= $templater->render();

		$templater = vB_Template::create('media_NAVTAB_sub');
		$templater->register('categoryID', $category['categoryID']);
		$templater->register('catName', $category['catName']);
		$submitbits .= $templater->render();
	}
}

$templater = vB_Template::create('media_NAVTAB');
$templater->register('categorybits', $categorybits);
$templater->register('submitbits', $submitbits);
$templater->register('submitperm', $submitperm);
$template_hook['navtab_middle'] .= $templater->render();
No matter what, $submitperm is always false...
Reply With Quote
  #71  
Old 09-16-2010, 07:57 PM
unknown22 unknown22 is offline
 
Join Date: Aug 2010
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where do I add these I know to create a new plugin?
Reply With Quote
Reply

Thread Tools

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 04:15 PM.


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.05320 seconds
  • Memory Usage 2,393KB
  • 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
  • (5)bbcode_code
  • (6)bbcode_html
  • (7)bbcode_php
  • (1)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
  • (11)post_thanks_box
  • (4)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
  • (2)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