• Welcome to Simple Machines Community Forum. Please login or sign up.
December 05, 2021, 10:00:40 AM

News:

Want to get involved in developing SMF, then why not lend a hand on our github!


[1.1] How to add tabs to Core (NDT)?

Started by JayBachatero, December 31, 2005, 04:21:57 PM

Previous topic - Next topic

JayBachatero

December 31, 2005, 04:21:57 PM Last Edit: January 15, 2009, 05:12:45 PM by H
For a more up to date version of this please see the doc site
SMF 2.0? See here instead

The way you add links to the menu has changed in the new default theme.  You will need to make several other steps in order to make the tabs work like they should.  Here are the steps required to add a menu item.  For this tutorial we are going to be adding a chat link.

1. In index.template.php
There are two ways to do this.  This first method is the recomemded one.

First method
Code (Find) Select
if ($context['current_action'] == 'search2')
$current_action = 'search';


Code (Add After) Select
if ($context['current_action'] == 'chat')
$current_action = 'chat';


Second Method
Code (Find) Select
if (in_array($context['current_action'], array('search', 'admin', 'calendar', 'profile', 'mlist', 'register', 'login', 'help', 'pm')))

As you can see it has a list of the actions in the menu.  What we are going to do is add , 'chat' after 'pm'.  Each action in the array is separated by a comma and enclosed in single quotes (').  It should look like this.

if (in_array($context['current_action'], array('search', 'admin', 'calendar', 'profile', 'mlist', 'register', 'login', 'help', 'pm', 'chat')))


The next step is adding the link itself.  This is an example of the home menu.

2. In the same file

// Show the [home] button.
echo ($current_action=='home' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'home' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '">' , $txt[103] , '</a>
</td>' , $current_action == 'home' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';




  • $current_action=='home' - is what sets the tab for the current actions.  As you can see it is defined in 3 instances.  You will need to change it for all three of them.
  • ' , $txt[103] , ' - is the text string that 'Home'.  As you see the variable is insde ' , , '.  The reason for this is because it's inside an echo.  If you are going to hard code the name in the menu you do not need to put ' , , ' around it.

This is how it should look with the made changes.


// Show the [chat] button.
echo ($current_action=='chat' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'chat' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '?action=chat">Chat</a>
</td>' , $current_action == 'chat' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';



If you want to be neat about it and add support for other languages add this string to /Themes/default/languages/index.english.php and to any other language file that you want to add it to.  ie. /Themes/default/languages/index.{language}.php and change Chat to the translated string.
$txt['chat'] = 'Chat';


EDIT
I cleaned this tutorial up a bit.

If you find it a bit confusing please let me know so that I can recide it :)

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

J. Williams

Best sticky this as its very important
Joshua Jon Williams
Back in Action.

JayBachatero

Meh too many stickies in this board.  Let it float around.  People will find it and it's not that difficult to add them ;)

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

J. Williams

Joshua Jon Williams
Back in Action.

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

J. Williams

Joshua Jon Williams
Back in Action.

JayBachatero

If it becomes an issue it will be put as a sticky for a week or two :)

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Simplemachines Cowboy

Mine is close:
// Show the [chat] button.
if ($context['user']['is_logged'])
echo ($current_action=='chat' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'chat' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '?action=chat">' , $txt[100] , '</a>
</td>' , $current_action == 'chat' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';


You'll notice I made a new $txt[100] that says 'Chat' & put it in index.english

Cowboy
My SMF forum: The Open Range

JayBachatero

Yeah it's better to add it to the language files than hardcoding the text to the link :)  make sure that $txt[100] is not used some where else.

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Simplemachines Cowboy

Since I'm currently on a test board I didn't scan EVERYWHERE for another $txt[100] but it seems to work.

A little OT but I plan to do a tutorial showing how to add everything to integrate Flashchat into RC 2. It's time to update the old one.
My SMF forum: The Open Range

JayBachatero

For things like this I would suggest that you use custom strings like $txt['chat_1'] and so on.  To prevent errors and so on.

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

russ skinner

I would like to add a gallery button to link to a coppermine gallery (to open in a seperate window) and have the button only visible once the user has logged on to the forum. In index.template.php I've modified the list of actions as follows:

Quoteif (in_array($context['current_action'], array('search', 'admin', 'calendar', 'profile', 'mlist', 'register', 'login', 'help', 'pm', 'gallery')))

but I am unsure how to code the link.

My forum is at http://www.srcmc.co.uk/forum/index.php and my gallery at http://www.srcmc.co.uk/gallery/index.php

Can anybody please help.

Many thanks

JayBachatero

January 01, 2006, 06:21:16 PM #12 Last Edit: January 01, 2006, 06:27:31 PM by JayBachatero
Add if ($context['user']['is_logged']) Before the button like this.


	
// Show the [chat] button.
	
if (
$context['user']['is_logged'])
	
echo (
$current_action=='chat' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' $first '">&nbsp;</td>' '' '
	
	
	
	
<td valign="top" class="maintab_' 
$current_action == 'chat' 'active_back' 'back' '">
	
	
	
	
	
<a href="'
$scripturl'">Chat</a>
	
	
	
	
</td>' 
$current_action == 'chat' '<td class="maintab_active_' $last '">&nbsp;</td>' '';


-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

russ skinner

Many thanks.

It works perfectly.

Russell

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

TarantinoArchives


Gargoyle

How do I make it link to an offsite URL... Like a Gallery or another website all together ?

JayBachatero

Just edit the href tag. <a href="', $scripturl, '?action=chat">Chat</a>.  If you are making it to an outside site you dont have to do the action stuff in if (in_array($context['current_action'], array('search',...

-JayBachatero
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Gargoyle


JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Advertisement: