News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

SMF2.0 - modifying theme to add menu-bar buttons

Started by splashmonkey, November 29, 2009, 12:24:35 PM

Previous topic - Next topic

splashmonkey

Hi

I run a forum on SMF1.1.10 and have a few extra buttons in my menu-bar (see attached) which link to external pages: these are configured in index.template.php and work fine. When running a test of the upgrade to SMF2.0 I noticed that the old them is rather badly mangled (which isn't a problem - this kind of thing I expect from a major version release!) so I was looking to add them back in, and I believe I need to add them into Boardindex.template.php however I'm a little stuck as to how to go about this - what format should these links take, and where in the file should they reside?

I hope this all makes sense - if not please feel free to ask away and I'll be more than happy to give any answers I can.

Thanks in advance for any assistance you can provide!

forsakenlad

Its index.template.php and the part you need to change is:

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

echo '
<div id="main_menu">
<ul class="dropmenu" id="menu_nav">';

foreach ($context['menu_buttons'] as $act => $button)
{
echo '
<li id="button_', $act, '">
<a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
<span class="', isset($button['is_last']) ? 'last ' : '', 'firstlevel">', $button['title'], '</span>
</a>';
if (!empty($button['sub_buttons']))
{
echo '
<ul>';

foreach ($button['sub_buttons'] as $childbutton)
{
echo '
<li>
<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
<span', isset($childbutton['is_last']) ? ' class="last"' : '', '>', $childbutton['title'], !empty($childbutton['sub_buttons']) ? '...' : '', '</span>
</a>';
// 3rd level menus :)
if (!empty($childbutton['sub_buttons']))
{
echo '
<ul>';

foreach ($childbutton['sub_buttons'] as $grandchildbutton)
echo '
<li>
<a', $grandchildbutton['active_button'] ? ' class="active"' : '', ' href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
<span', isset($grandchildbutton['is_last']) ? ' class="last"' : '', '>', $grandchildbutton['title'], '</span>
</a>
</li>';

echo '
</ul>';
}

echo '
</li>';
}
echo '
</ul>';
}
echo '
</li>';
}

echo '
</ul>
</div>';
}
Eren "forsakenlad" Yaşarkurt
SMF Friend & Former Team Member

splashmonkey

#2
Many thanks forsakenlad - and now for the really pathetic part... How do I actually code the links/buttons? I'm somewhere below a slug in terms of PHP skills I'm afraid :(


EDIT - ok, scratch that - while searching around I found http://www.simplemachines.org/community/index.php?topic=261880.0 which would seem to do exactly as I need, so I've added a couple of buttons in the format


),
),
'ventrilo' => array(
'title' => $txt['ventrilo'],
'href' => 'http://www.seedsofglory.net/ventrilo.htm',
'show' => true,
'sub_buttons' => array(
),


however I'm now getting

QuoteParse error: syntax error, unexpected ';', expecting ')' in E:\xampp\xampp\htdocs\sog\Sources\Subs.php on line 4010

Line 4010 being the end of the section (ie immediately before "// Now we put the buttons in the context so the theme can use them."). Any ideas?

forsakenlad

Navigate to the end of the function, you'll see something like this:

   echo '
         </ul>
      </div>';


Replace it like this adding the links you want:

echo '
<li><a class="firstlevel" href="#"><span class="firstlevel">Menu</span></a></li>
<li><a class="firstlevel" href="#"><span class="firstlevel">Menu2</span></a></li>
</ul>
</div>';
Eren "forsakenlad" Yaşarkurt
SMF Friend & Former Team Member

splashmonkey

gah, my last update error has been fixed by correcting my shoddy typing... I now have the buttons available, I just don't have any text on them. I'll re-read that howto and see if I can get it working :)

Thanks for your help thus far forsakenlad!

forsakenlad

Plese follow *my* instructions, they are pretty straight forward.
Eren "forsakenlad" Yaşarkurt
SMF Friend & Former Team Member

splashmonkey

Indeed they are, and they seem to work fine. Only one gotcha though (and I'm sure it's something simple!) - the extra buttons appear after the "logout" button. Is there an easy way to change the location so that they appear between "Members" and "Logout"?

Thanks again for you help - it really is appreciated.

forsakenlad

For that you'll have to modify Subs.php, the way H described it in his topic.
Eren "forsakenlad" Yaşarkurt
SMF Friend & Former Team Member

thunder63cs

#8
I am having the same issue with buttons being there but no text.  ok by dumb luck I fouind the fix for it when I added this code:

         'wiki' => array(
             'title' => $txt['Wiki'],
             'href' => 'http://',
             'show' => true,
             'sub_buttons' => array(
             ),
          ),

fixed the title not showing up but making it look like this:

         'wiki' => array(
             'title' => 'Wiki',
             'href' => 'http://',
             'show' => true,
             'sub_buttons' => array(
             ),
          ),
and now it all works. 

Advertisement: