SMF Support > SMF 2.0.x Support

$context menu links?

(1/2) > >>

Hi guys. This isn't a bug report or an error.

Ive been trying to add a new link to my menu bar up the top of my forum. This isn't as easy as adding a new HREF.
Ive searched through a lot of the code but i cant seam to find where the menu links are stored.. in the template files it loops through a variable called $context['menulinks'] or something as such. But i cant find where this is being set.

I was wondering if someone could point me in the right direction for adding a new menu link that only my members see?


In the templates I have used there has been separate ways of creating links. I use my own script for creating site links so I have no reference, could you please post the loop you talk of.

You could do a hacky fix and simple add the link before it loops. Or if you want to move it somewhere, loop through with an if statement to detect after which link you want it and insert the new values into the array.

In index.template.php of the default template.

--- Code: ---// Show the menu up top. Something like [home] [help] [profile] [logout]...
function template_menu()
global $context, $settings, $options, $scripturl, $txt;

// Are we using right-to-left orientation?
if ($context['right_to_left'])
$first = 'last';
$last = 'first';
$first = 'first';
$last = 'last';

// Show the start of the tab section.
echo '
<table cellpadding="0" cellspacing="0" border="0" style="margin-left: 10px;">
<td class="maintab_' , $first , '">&nbsp;</td>';

foreach ($context['menu_buttons'] as $act => $button)
echo ($button['active_button'] || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , ' <td valign="top" class="maintab_', $button['active_button'] ? 'active_back' : 'back', '">
<a href="', $button['href'], '">', $button['title'], '</a>
</td>', $button['active_button'] ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';

// The end of tab section.
echo '
<td class="maintab_' , $last , '">&nbsp;</td>

--- End code ---

foreach ($context['menu_buttons'] as $act => $button)

It loops through $context['menu_buttons']
I want to be able to add another button to the array if the user is logged in.. But i cant find where the array is being set.

Go into Sources/Subs.php and look at the function setupMenuContext(). It is on line 3652 for me.

Then add to the $buttons array on line 3670 your new button. Title and href are self explanatory and for show you would do this...

'show' => !$user_info['is_guest'],

Hi Andy and welcome to SMF.

Hope I'm not off track here, but are you just trying to add a new navigation link in your forum (ex: Home, Help, Members, etc.)? If so, it's just a matter of copying the existing code it has there for the buttons and modifying it to suit your needs.

How do you add custom tabs to the Core (default) theme menu?

Are you using the default theme or a custom one?


[0] Message Index

[#] Next page

Go to full version