• Welcome to Simple Machines Community Forum. Please login or sign up.
September 24, 2021, 08:50:57 AM

News:

Want to get involved in developing SMF, then why not lend a hand on our github!


$context menu links?

Started by RNAndyB, July 19, 2008, 10:59:29 AM

Previous topic - Next topic

RNAndyB

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

Robbo_

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.
Aus-Newerth

Quote from: IRC
Roph> I just finished a double 1/2lb cheese, bacon & salad beef burger
Roph> no woman on earth could satisfy me as much as I am satisfied right now by this burger
... later on ...
Roph> how could ensie go about satisfying me =o
<Ensiferous> Roph: Merely looking at me would yield far more pleasure than a burger can provide.

RNAndyB

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.

Robbo_

July 20, 2008, 04:40:10 AM #3 Last Edit: July 20, 2008, 04:42:17 AM by Robbo_csp
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'],
Aus-Newerth

Quote from: IRC
Roph> I just finished a double 1/2lb cheese, bacon & salad beef burger
Roph> no woman on earth could satisfy me as much as I am satisfied right now by this burger
... later on ...
Roph> how could ensie go about satisfying me =o
<Ensiferous> Roph: Merely looking at me would yield far more pleasure than a burger can provide.

greyknight17

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?

RNAndyB

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.

Advertisement: