News:

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

Main Menu

Add a Site Home Button at the Top

Started by Slushie, July 20, 2007, 11:44:40 PM

Previous topic - Next topic

Slushie

Hey,

I want to add a button at the top of my forum, next to the "home", "help" "search" etc. buttons. I want this button to simply lead back to my main site, so visitors don't have to type in the site url.

My Template is based off the the Classic Style Theme. I'm using SMF 1.1.3, but my template is 1.1. Made it long ago, and have just left it, everything still seems to work fine.

Well, can anyone help me add this button?

Below is part of my index.template, where I'm guessing it needs to be edited, because I see the other buttons are there, but I don't know PHP, so I don't really want to fiddle with it.

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

   // Show the [home] and [help] buttons.
   echo '
            <a href="', $scripturl, '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/home.gif" alt="' . $txt[103] . '" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=help" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/help.gif" alt="' . $txt[119] . '" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];

   // How about the [search] button?
   if ($context['allow_search'])
      echo '
            <a href="', $scripturl, '?action=search">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/search.gif" alt="' . $txt[182] . '" border="0" />' : $txt[182]), '</a>', $context['menu_separator'];

   // Is the user allowed to administrate at all? ([admin])
   if ($context['allow_admin'])
      echo '
            <a href="', $scripturl, '?action=admin">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];

   // Edit Profile... [profile]
   if ($context['allow_edit_profile'])
      echo '
            <a href="', $scripturl, '?action=profile">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/profile.gif" alt="' . $txt[79] . '" border="0" />' : $txt[467]), '</a>', $context['menu_separator'];

   // The [calendar]!
   if ($context['allow_calendar'])
      echo '
            <a href="', $scripturl, '?action=calendar">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/calendar.gif" alt="' . $txt['calendar24'] . '" border="0" />' : $txt['calendar24']), '</a>', $context['menu_separator'];

   // If the user is a guest, show [login] and [register] buttons.
   if ($context['user']['is_guest'])
   {
      echo '
            <a href="', $scripturl, '?action=login">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/login.gif" alt="' . $txt[34] . '" border="0" />' : $txt[34]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=register">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/register.gif" alt="' . $txt[97] . '" border="0" />' : $txt[97]), '</a>';
   }
   // Otherwise, they might want to [logout]...
   else
      echo '
            <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/logout.gif" alt="' . $txt[108] . '" border="0" />' : $txt[108]), '</a>';
}

// Generate a strip of buttons, out of buttons.
function template_button_strip($button_strip, $direction = 'top', $force_reset = false, $custom_td = '')
{
   global $settings, $buttons, $context, $txt, $scripturl;

   if (empty($button_strip))
      return '';

   // Create the buttons...
   foreach ($button_strip as $key => $value)
   {
      if (isset($value['test']) && empty($context[$value['test']]))
      {
         unset($button_strip[$key]);
         continue;
      }
      elseif (!isset($buttons[$key]) || $force_reset)
         $buttons[$key] = '<a href="' . $value['url'] . '" ' .( isset($value['custom']) ? $value['custom'] : '') . '>' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . ($value['lang'] ? $context['user']['language'] . '/' : '') . $value['image'] . '" alt="' . $txt[$value['text']] . '" border="0" />' : $txt[$value['text']]) . '</a>';

      $button_strip[$key] = $buttons[$key];
   }

   echo '
      <td ', $custom_td, '>', implode($context['menu_separator'], $button_strip) , '</td>';
}

?>


Thanks.

codenaught

Change this code:


   echo '
            <a href="', $scripturl, '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/home.gif" alt="' . $txt[103] . '" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=help" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/help.gif" alt="' . $txt[119] . '" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];


To:


   echo '
            <a href="http://www.yoursiteaddress.com">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/site.gif" alt="Site" border="0" />' : 'Site'), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/home.gif" alt="' . $txt[103] . '" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=help" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/help.gif" alt="' . $txt[119] . '" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];


Changing http://www.yoursiteaddress.com to your site address. You will also have to have an image called 'site.gif' in Themes/<theme_name>/images. Do you have an button image you want to use already?
Dev Consultant
Former SMF Doc Coordinator

Slushie

THANKS! :D It worked perfectly.

After I posted this topic, I went and made a site button, named it site.gif and uploaded it. Came back here, saw the instructions, changed it, and uploaded it.

Thanks again. Really helped me. :)

thurmag

With this same code in mind, is it possible to enter a NEW button between the "Calendar" & "Logout" buttons to do basically the same thing... go to a web site address?  Our will there need to be "more" coding involved?

Thanks...

-Gary-

codenaught

Sure, you would locate the menu code for calendar and logout and insert a menu item for your custom link.

Have you seen this document? http://docs.simplemachines.org/index.php?topic=564.0

If you need more help, let us know, and it may be handy for you to then provide the menu code your currently have.
Dev Consultant
Former SMF Doc Coordinator

thurmag

#5
Thank you akabugeyes!

I copied the menu section code from the "index.template.php" file below.  I'd like to add a couple of new menu buttons (that would take you to a different web site), which would be activated by clicking on a graphic button (much like the home.gif, help.gif, etc... buttons).  I have made the different "buttons.gif" files already. 

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

   // Show the [home] and [help] buttons.
   echo '
            <a href="', $scripturl, '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/home.gif" alt="' . $txt[103] . '" style="margin: 2px 0;" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=help" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/help.gif" alt="' . $txt[119] . '" style="margin: 2px 0;" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];

   // How about the [search] button?
   if ($context['allow_search'])
      echo '
            <a href="', $scripturl, '?action=search">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/search.gif" alt="' . $txt[182] . '" style="margin: 2px 0;" border="0" />' : $txt[182]), '</a>', $context['menu_separator'];

   // Is the user allowed to administrate at all? ([admin])
   if ($context['allow_admin'])
      echo '
            <a href="', $scripturl, '?action=admin">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" style="margin: 2px 0;" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];

   // Edit Profile... [profile]
   if ($context['allow_edit_profile'])
      echo '
            <a href="', $scripturl, '?action=profile">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/profile.gif" alt="' . $txt[79] . '" style="margin: 2px 0;" border="0" />' : $txt[467]), '</a>', $context['menu_separator'];

   // The [calendar]!
   if ($context['allow_calendar'])
      echo '
            <a href="', $scripturl, '?action=calendar">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/calendar.gif" alt="' . $txt['calendar24'] . '" style="margin: 2px 0;" border="0" />' : $txt['calendar24']), '</a>', $context['menu_separator'];

   // If the user is a guest, show [login] and [register] buttons.
   if ($context['user']['is_guest'])
   {
      echo '
            <a href="', $scripturl, '?action=login">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/login.gif" alt="' . $txt[34] . '" style="margin: 2px 0;" border="0" />' : $txt[34]), '</a>', $context['menu_separator'], '
            <a href="', $scripturl, '?action=register">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/register.gif" alt="' . $txt[97] . '" style="margin: 2px 0;" border="0" />' : $txt[97]), '</a>';
   }
   // Otherwise, they might want to [logout]...
   else
      echo '
            <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/logout.gif" alt="' . $txt[108] . '" style="margin: 2px 0;" border="0" />' : $txt[108]), '</a>';
}

So after looking at the code provided in the other post, for a new button that would go to a different website, it should look something like the below example... right?  Would I have to add coding to another file to tell it WHERE to add the new buttons on the menu?  Or by placing this code in between the other menu codes should do this?

Quote
   echo '
            <a href="http://www.yoursiteaddress.com">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/yoursite.gif" alt="' . $txt[103] . '" style="margin: 2px 0;" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '

Thanks again...

-Gary-

Gary

Thats pretty much it, Gary. Just add that code:

   echo '
            <a href="http://babysimpson.co.uk">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/tcb.gif" alt="' . $txt[103] . '" style="margin: 2px 0;" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '


into your index.template.php and upload the button (tcb.gif in this example) into your Themes/[THEME]/images/[LANGUAGE] folder.

You may also wanna add target="_blank" to the <a href= though. :P

-Gary M. Gadsdon, aka Gazmanafc
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

thurmag

Gazmanafc,

Thanks so much!  I edited the "index.template.php" file, and added the following code to create the New Menu Button!   :P  It actually worked!

Here is the code I entered:

Quoteecho '
            <a href="http://www.thenewsite.com" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/newsite.gif" alt="' . $txt[119] . '" style="margin: 2px 0;" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];

After coding this information, I uploaded my newly created button gif into the Themes/[Theme]/images/[Language] folder, and... everything worked!   8)

The only "minor" issue, is that the "$txt[119]" should be changed to what the button name is, as this produces the Text Word "Help" if there is no button gif.  Where is the file that these codes are defined at. 

Thanks for all of your help... you have really helped to make life a lot easier for the administrators, and members!   ;)

-Gary-

Gary

They're defined in the /language/index.language.php file in the default theme. If your website is English only, then you might as well just hard code it in, and replace ' , $txt[119] , ' with whatever the word would actually be. Instead of using a string.
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

thurmag

Quote from: Gazmanafc on November 14, 2007, 09:09:41 AM
They're defined in the /language/index.language.php file in the default theme. If your website is English only, then you might as well just hard code it in, and replace ' , $txt[119] , ' with whatever the word would actually be. Instead of using a string.

That did it!  You guys are "Awesome"! 

Thanks once again...

-Gary Thurman-

thurmag

#10
One last question (something new).   :P  We would like to add an additional line of menu buttons (right under the main Forum buttons), and the <P> command or <HR> commands don't seem to be working...

I just found out that adding more menu buttons, will cause the newer buttons to "Word Wrap" to the next line, but we would like to add a different colored set of menu buttons on a separate row, and leave the main Forum Software buttons on the upper line.

Any help would be appreciated.

Thanks...

-Gary-

*** We got it... never mind!  This is what was used: echo '<br />';

Advertisement: