Custom tabs - How do I add them to the Core (default) theme menu

From Online Manual

Jump to: navigation, search

Please refer to the FAQ How do I add buttons to SMF 2.0? for a description of how to create a new menu item for SMF 2.x

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.

In index.template.php

The index.template.php file can be found in: Themes/[theme-name]/index.template.php

The theme name is the name of the theme you want to edit. If there is no index.template.php there (which is unlikely, but might be), you should use the "default" theme directory.

There are two ways to do this. This first method is the recommended one.

First method

In the index.template.php file, find the following code:

if ($context['current_action'] == 'search2')
		$current_action = 'search';

And add below this:

if ($context['current_action'] == 'chat')
		$current_action = 'chat';

Second Method

In the index.template.php file, find:

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 . '"> </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 . '"> </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 prints Home on the Main menu. As you see the variable is inside ' , , '. 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 . '"> </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 . '"> </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';


For Support please take a look at this topic.