SMF Online Manual

*
  • Home
  • Community
  • Download
  • Customize
    • Modifications
    • Themes
    • Upgrades
  • Support
    • Function Database
  • Online Manual
  • About
  • Contribute
  • Development
 

Documentation of the moment:

Join the Doc Helpers group


  • Home
  • Help
  • Search
  • Login
  • Register

  • SMF Online Manual »
  • Glossary »
  • FAQs »
  • Theme Questions »
  • Topic: How do you add custom tabs to the Core (default) theme menu?
 
Install SMF Installing Upgrading Converting
Using SMF User Moderator Administrator
Advanced Mods and Themes More Info
Glossary Terminology FAQs References Feature List What's New
Comments Feedback Requests

Updated Documentation: The Online Manual has moved. All updates to the documentation are now taking place in the new Online Manual. Please see the new Online Manual, and learn how you can help, as it continues to grow and improve.

Updated content on Wiki: This documentation is outdated, please refer to the wiki article for more up to date information.

« previous next »
How do you add custom tabs to the Core (default) theme menu?
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 recommended 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.

Code: [Select]
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
Code: [Select]
// 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 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.

Code: [Select]
// 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';


For Support please take a look at this topic.
Print
Reply
Reply with quote



Comments:
tschieb1 made the following comment on February 10, 2007, 11:43:20 AM:

How can I add a link in to main forum manu but to open (flash chat) that link in a new window of my own dimensions (500px, 400px)

Thank you for your time and help
Tomislav :)

akabugeyes made the following comment on February 11, 2007, 02:35:55 PM:

Quote from: tschieb1 on February 10, 2007, 11:43:20 AM
How can I add a link in to main forum manu but to open (flash chat) that link in a new window of my own dimensions (500px, 400px)

Thank you for your time and help
Tomislav :)
Please post all support questions at http://www.simplemachines.org. Thank you.

chitlar made the following comment on September 27, 2008, 07:46:22 PM:

I cann't understand how to made ?

Jade made the following comment on September 28, 2008, 03:05:59 PM:

Use the first method in step one, then continue to step two :)

chitlar made the following comment on October 03, 2008, 01:27:42 PM:

Quote from: Jade on September 28, 2008, 03:05:59 PM
Use the first method in step one, then continue to step two :)

How to add custom link in new menu ?

Jade made the following comment on October 03, 2008, 11:01:47 PM:

Change this line from the doc to have your own link:

Code: [Select]
<a href="', $scripturl, '?action=chat">Chat</a>
Like:
Code: [Select]
<a href="LINK HERE">CLICK HERE</a>

Tarzan1 made the following comment on January 19, 2009, 05:12:12 PM:

Thanks for the instructions! I appreciate your efforts, however, you guys are so advanced in this stuff that you answer as if we all know something about php. Play along with me for a minute and perhaps you can understand where a lot of us are coming from:

Let's say you are at the dentist's office and there is a patient in the chair with a cavity. The dentist explains to you in detail how to drill out the absess, then hands you the drill and says, "Go ahead and put in a filling."

Umm... Ok, but where do you keep the amalgum and what does it look like? Do I need to mix it first? What utensils do I use and how do I apply it?

What the poor patient will end up with in his mouth will be anyone's guess! So... I'm going to try and help you to help so many others like myself, if you are willing:

First, let's help find the start of the code in your first step: Look for the comment

Code: [Select]
//Work out where we currently are.This will be about half way down the page in the index.template.php file that is located in the default styles folder.

Then do what you said in step one. Forget about the second way of doing it for now... it only confuses things. (The second way should be a complete new description.)

Follow with your second step.

Now here is the missing stuff: You nicely explain about
Code: [Select]
',$txt[103],'but you don't say HOW or WHAT to do about it!



Jade made the following comment on October 04, 2008, 03:01:47 AM:
Change this line from the doc to have your own link:

Code: [Select]
[Select]
<a href="', $scripturl, '?action=chat">Chat</a>
Like:
Code: [Select]
[Select]
<a href="LINK HERE">CLICK HERE</a>
I followed his advice, but I also went on to read about adding the line
Code: [Select]
if ($context['user'][is_logged']just under the comment
Code: [Select]
//Show the [home] button.So since I want only logged-in members to see my button, I used this line as well. When I uploaded the file to my bulletin board, I got a server parse error. I commented out all of my added lines done in part 1. Still the error, so I commented out the part for being logged in and the buttons (I added 2 of them) showed up and they work, but of course they show up for everybody.

I also read that php is an easy language to learn, making it easy to write BAD CODE! I don't wish to write bad code, so I would REALLY appreciate if one of you gurus could help me (and many others like me) do this thing correctly.

It seems that by hard coding my URLS into part 2 I don't need part 1 at all. Is this a valid assumption or is it false? Should I put them back?

What I am trying to do is what I see many others are looking for. I want to add link buttons to other pages OUTSIDE of SMF. In my case, a button to the HTML home page and a button for a photo gallery. With your part 1 commented out, what I have is
Code: [Select]
// 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>' : '';

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

// Show the [gallery] button.
        if ($context['user'][is_logged']
echo ($current_action=='gallery' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'gallery' ? 'active_back' : 'back' , '">
<a href="http://my_website.com/gallery/index.php">Photo Gallery</a>
</td>' , $current_action == 'gallery' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';

The above gives a server parse error, but with the line for user being logged in taken out, it works; but of course I now don't achieve my objective.
 :-\

Now let's go back to your second method. If you add your new buttons to the string, do you still do part 2 or is that it? This is why I say to keep the 2 methods entirely separate. The obvious to you is NOT the obvious to many of us.

Would someone please (with sugar on top) sort this out once and for all?

Thanks in advance!

Jade made the following comment on January 19, 2009, 06:55:12 PM:

You made a mistake:

FIND:

Code: [Select]
        if ($context['user'][is_logged']
REPLACE:
Code: [Select]
        if ($context['user']['is_logged'])
You should do part one (method one OR two) and part two :).

WBA Dude made the following comment on June 28, 2009, 08:52:17 AM:

What happens if you want the tab to lead to a html page?

B made the following comment on July 15, 2009, 01:31:14 PM:

Simply change this line from Step 2:

Code: [Select]
               <a href="', $scripturl, '?action=chat">Chat</a>

to use whatever address you want. Like this:

Code: [Select]
               <a href="http://www.google.com">Chat</a>

B

erkan made the following comment on March 05, 2010, 02:20:23 PM:

may i know if this way same for SMF 2.0 RC2 coz i cant find these codes to replace with ?

yangtastic made the following comment on April 30, 2010, 04:04:56 AM:

I tried this method out and it won't let me create a button that has two seperate phrases. eg. "About Us". Is there anyway I could create a tab like this? If there is, how?

Harry77 made the following comment on June 10, 2010, 10:12:13 AM:

How can I go to index.template.php?

xaris95 made the following comment on July 06, 2010, 05:31:17 AM:

Hey I have put a button named CHAT to lead to http://forum.mywebsite.tdp/chat but when I click the button it does not transfer me to the link.
I have replaced this code:

Code: [Select]
<a href="', $scripturl, '?action=chat">Chat</a>
with this according to your instructions:
Code: [Select]
<a href="', $scripturl, '?action=http://forum.gamato.biz/chat">chat</a>
all the other code that I have added is like your examples!

Seek made the following comment on August 24, 2010, 04:26:11 PM:

Well let me get this straight...I did the first method and I've got a beautiful error that tells me the index.template.php is not good.
I tried this on babylon theme. So my question is "do I have to go trough both methods or if I'm using just the first one is OK"...

Acans made the following comment on August 29, 2010, 01:29:30 AM:

@Erken

Follow this tutorial for 2.0 RC3: http://www.simplemachines.org/community/index.php?topic=261880.0

@yangtastic, Harry77, xaris95, Seek

Please post your support questions with your smf version at www.simplemachines.org/community.

If any of you are using 2.0, than follow this tutorial. http://www.simplemachines.org/community/index.php?topic=261880.0


Advertisement:
  • SMF 2.0.1 | SMF © 2011, Simple Machines
  • XHTML
  • WAP2

Page created in 1.449 seconds with 21 queries.
Page served by: 10.0.100.112