Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: RNAndyB on July 19, 2008, 10:59:29 AM

Title: $context menu links?
Post by: RNAndyB on July 19, 2008, 10:59:29 AM
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?

Thanks.
Andy
Title: Re: $context menu links?
Post by: Robbo_ on July 19, 2008, 11:28:43 AM
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.
Title: Re: $context menu links?
Post by: RNAndyB on July 19, 2008, 02:49:44 PM
In index.template.php of the default template.

// 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';
}
else
{
$first = 'first';
$last = 'last';
}

// Show the start of the tab section.
echo '
<table cellpadding="0" cellspacing="0" border="0" style="margin-left: 10px;">
<tr>
<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>
</tr>
</table>';

}


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.
Title: Re: $context menu links?
Post by: Robbo_ on July 20, 2008, 04:40:10 AM
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'],
Title: Re: $context menu links?
Post by: greyknight17 on July 20, 2008, 04:00:25 PM
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? (http://docs.simplemachines.org/index.php?topic=564)

Are you using the default theme or a custom one?
Title: Re: $context menu links?
Post by: RNAndyB on July 20, 2008, 06:16:02 PM
Thank you. This works like a charm.

Sorry for the newbie questions. Ive crossed over from other packages.. so still getting used to the workings of smf.