Adding buttons to the main menu in SMF 2.0

Started by noquiexis, July 23, 2010, 10:24:39 PM

Previous topic - Next topic

noquiexis

     The documentation for adding buttons to the main menu http://docs.simplemachines.org/index.php?topic=1032.0 does not work with version 2.0.
     I culled these instructions from Add Link to Main Website Page .... Thanks to Augster, xenovanis, and capady:)

1. Add a new button in /Sources/Subs.php:

     Search for the home button near the bottom of the page. You should see this:

// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
{
$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => $scripturl,
'show' => true,
'sub_buttons' => array(
),
'is_last' => $context['right_to_left'],
// 'target' => '_blank',
),
'help' => array(
'title' => $txt['help'],
'href' => $scripturl . '?action=help',
'show' => true,
'sub_buttons' => array(
),
),


2. Highlight and copy everything from 'help' => array(" to the final ),  before the next section ('search').

3. Paste the section that you copied between any two existing buttons.
Note: The home" and "logout buttons contain the statement:

'is_last' => $context['right_to_left'],

     If you want your new button to be in front of home or behind logout, you must move this statement to the first or last button.

4. Change the text for your new button, as in this example:

'chat' => array(
'title' => $txt['chat'],
'href' => 'chat/index.php',
'show' => true,
'sub_buttons' => array(
),
),


     Notice that the 'href' => 'chat/index.php', in the above example goes to a subdirectory. To link to an external website, include the full URL:

'http://www.my_ISP.net/~my_website/'

5a. If you want to have the page open in a new window, make this change:

'href' => 'chat/index.php "target="_blank',

5b. To change the text to an image, use this example posted by cicka:

Change: 'title' => $txt['chat'],
to: 'title' => '<img src="' . $settings['images_url'] . 'chat/chat_icon.gif">',

The chat/chat_icon.gif is the directory and filename of the image.

6. The space for the link is there now, but to make the text or image show, go to the directory Themes/default/languages/ and find every file that looks like this: Modifications.some_language.php Add this code to all of these files:

$txt['chat'] = 'Chat';

     Using the "chat" example, I added this to Modifications.english.php.
The lettercase is exactly how you format it. Be careful!

7. If the new button does not show, try clearing the file cache:

Go to Admin->Maintenance->Forum Maintenance->Routine, and select last item EMPTY THE FILE CACHE.
"To me the meanest flower that blows can give
 Thoughts that do often lie too deep for tears."

    William Wordsworth

Kill Em All

A guide, if not two other guides have already been posted on how to do this. I would link them but I lost my bookmarks for some reason on this computer. But thank you very much for giving tips on adding buttons. Sometimes it just takes a certain way to explain things. So your way might be better for others. :)


My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

davyj


anakmacan


kurian

Quote from: Kill Em All on July 24, 2010, 12:18:16 AM
Change: 'title' => $txt['chat'],
to: 'title' => '<img src="' . $settings['images_url'] . 'chat/chat_icon.gif">',
hello, im trying this option but no work, i did var_dump of $setting in function setupMenuContext() and it is NULL. Anyone can help me?

Thank

Suki

thats probably because $settings isn't globalize in the function

try adding  $settings,  to the globals:

function setupMenuContext()
{
   global $context, $modSettings, $user_info, $txt, $scripturl;




function setupMenuContext()
{
   global $context, $modSettings, $user_info, $txt, $scripturl, $settings;
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Making tough decisions, so you don't have to.

kurian

Quote from: Miss All Sunday on May 30, 2011, 12:19:28 PM
thats probably because $settings isn't globalize in the function

try adding  $settings,  to the globals:

function setupMenuContext()
{
   global $context, $modSettings, $user_info, $txt, $scripturl;




function setupMenuContext()
{
   global $context, $modSettings, $user_info, $txt, $scripturl, $settings;

Thanks you! it was the problem.

Wilo

Hi,

I've followed the instructions to add a button to the menu but i only get an invisible button about a quarter the size of a normal button with no text.

Can anyone shed some light on what I'm missing.

Many thanks,


Suki

you probably still need to add your txt string to your /Themes/default/languages/Index.yourlanguage.php  file
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Making tough decisions, so you don't have to.

quodvult

Hi,

I am using the Cracked theme, and can't find a file named sources/subs.php or anything like it - where should I access this menu buttons on this theme and would it be the same as what you have just described?


Kindred

the menu is not stored in the theme files any more (as of 2.0)
If your theme does it differently (i.e. is still building the menu directly in the template file) then you'll have to take it up with that theme author.
Слова
Украина

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: