News:

Wondering if this will always be free?  See why free is better.

Main Menu

Help with Custom Theme NavBar

Started by LC, September 25, 2009, 02:51:09 PM

Previous topic - Next topic

LC

I would like to add new buttons to the nav bar on a custom theme 1.1.10.

I assumed I could add them by copying another button's code and filling in the button info where needed. But it wont show up properly. It's like the script recognizes some of it but wont show up the rest.
I've had someone else show me once, but I can't remember since it's been a while how to manually make a new one. Most mods that offer buttons use a table code which this theme does not use. It uses the list code.

Here's the screenshot.


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

// Work out where we currently are.
$current_action = 'home';
if (in_array($context['current_action'], array('admin', 'ban', 'boardrecount', 'cleanperms', 'detailedversion', 'dumpdb', 'featuresettings', 'featuresettings2', 'findmember', 'maintain', 'manageattachments', 'manageboards', 'managecalendar', 'managesearch', 'membergroups', 'modlog', 'news', 'optimizetables', 'packageget', 'packages', 'permissions', 'pgdownload', 'postsettings', 'regcenter', 'repairboards', 'reports', 'serversettings', 'serversettings2', 'shop', 'smileys', 'viewErrorLog', 'viewmembers')))
$current_action = 'admin';
if (in_array($context['current_action'], array('shop','gallery','search', 'admin', 'calendar', 'profile', 'mlist', 'register', 'login', 'help', 'pm')))
$current_action = $context['current_action'];
if ($context['current_action'] == 'search2')
$current_action = 'search';
if ($context['current_action'] == 'theme')
$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
// Begin SMFShop code
if ($context['current_action'] == 'shop')
$current_action = 'shop';
if (in_array($context['current_action'], array('shop_general', 'shop_items_add', 'shop_items_edit', 'shop_cat', 'shop_inventory', 'shop_restock', 'shop_usergroup')))
$current_action = 'admin';
// End SMFShop code

// 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 '
  <div id="tab">
<ul>';

// Show the [home] button.
echo '<li', $current_action == 'home' ? ' class="chosen"' : '', '><a href="', $scripturl, '"><span>' , $txt[103] , '</span></a></li>';
// Show the [profilehelp] button.
echo '<li', $current_action == 'Profilehelp' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=Profilehelp"><span>' , $txt[''] , '</span></a></li>';
// How about the [search] button?
if ($context['allow_search'])
echo '<li', $current_action == 'search' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=search"><span>' , $txt[182] , '</span></a></li>';
// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '<li', $current_action == 'admin' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=admin"><span>' , $txt[2] , '</span></a></li>';
// Edit Profile... [profile]
if ($context['allow_edit_profile'])
echo '<li', $current_action == 'profile' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=profile"><span>' , $txt[79] , '</span></a></li>';
// Go to PM center... [pm]
if ($context['user']['is_logged'] && $context['allow_pm'])
echo '<li', $current_action == 'pm' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=pm"><span>' , $txt['pm_short'] , ' ', $context['user']['unread_messages'] > 0 ? '[<blink> '. $context['user']['unread_messages'] . ' </blink>]' : '' , '</span></a></li>';
// The [calendar]!
if ($context['allow_calendar'])
echo '<li', $current_action == 'calendar' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=calendar"><span>' , $txt['calendar24'] , '</span></a></li>';
// Show the [shop] button.
echo '<li', $current_action == 'shop' ? ' class="current"' : '', '><a href="', $scripturl, '?action=shop"><span>' , $txt['shop_general'] , '</span></a></li>';
// The [member] list button.
if ($context['allow_memberlist'])
echo '<li', $current_action == 'mlist' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=mlist"><span>' , $txt[331] , '</span></a></li>';
// the [SMF Gallery] button
if ($context['allow_smfgallery_view'])
echo '<li><a ' , $current_action=='gallery' ? ' class="current"' : '' , ' href="', $scripturl, '?action=gallery"><span>' , $txt['smfgallery_menu']  , '</span></a></li>';
// If the user is a guest, also show [register] button.
if ($context['user']['is_guest'])
echo '<li', $current_action == 'register' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=register"><span>' , $txt[97] , '</span></a></li>';
// If the user is a guest, show [login] button.
if ($context['user']['is_guest'])
echo '<li', $current_action == 'login' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=login"><span>' , $txt[34] , '</span></a></li>';
// Otherwise, they might want to [logout]...
if ($context['user']['is_logged'])
echo '<li', $current_action == 'logout' ? ' class="chosen"' : '', '><a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '"><span>' , $txt[108] , '</span></a></li>';
echo '
</ul>
  </div>';
}


What I want to know is where did I go wrong? How can I fix this by myself in order to add buttons when I need them? I'm still learning PHP so any help would be appreciated.

Regards,
LC

mashby

Guess it depends on the theme you are using. The Profile Help menu item has this bit in your code:
<a href="', $scripturl, '?action=Profilehelp"><span>' , $txt[''] , '</span>

$txt[''] is empty and as such results in a blank tab. The other blank tab has this:
<a href="', $scripturl, '?action=shop"><span>' , $txt['shop_general'] , '</span></a>

I'm going to guess that your custom theme has a /languages/modifications.english.php file which likely needs to have some language strings added to it (copying them from the default one).
Always be a little kinder than necessary.
- James M. Barrie

LC

Quote from: mashby on September 25, 2009, 06:31:57 PM
Guess it depends on the theme you are using. The Profile Help menu item has this bit in your code:
<a href="', $scripturl, '?action=Profilehelp"><span>' , $txt[''] , '</span>

$txt[''] is empty and as such results in a blank tab. The other blank tab has this:
<a href="', $scripturl, '?action=shop"><span>' , $txt['shop_general'] , '</span></a>

I'm going to guess that your custom theme has a /languages/modifications.english.php file which likely needs to have some language strings added to it (copying them from the default one).
No, this custom theme does not. :( It has Themestrings.english.php and settings.english.php in the languages folder. The theme I have been messing with is CS Cleaner. I also use Siyah_inci and both are having issues with this. I haven't officially allowed other members to use the CS Cleaner yet, since I am sorta using it as a learning tool for buttons.

I've been messing around with the two buttons, adding to the $text with the name of the button, but it refuses to show up properly. Sorry I forgot I left them blank when I added the code here. I've been trying numerous different ways, adding to the array, then adding the same to the current action= , the $text and $context strings.

I successfully at one point got the shop button to show, but this was only for the admins.

Antechinus

If you only want English on your site (or any other single language) you can hard code the text in index.template.

Example:

<a href="', $scripturl, '?action=Profilehelp"><span>Profile Help</span>

LC

Quote from: Antechinus on September 25, 2009, 07:00:31 PM
If you only want English on your site (or any other single language) you can hard code the text in index.template.

Example:

<a href="', $scripturl, '?action=Profilehelp"><span>Profile Help</span>

So I wouldn't need to use the $txt[''] or echo the (in_array($context['current_action']? If so that would make life so much easier. All of my members are either from the UK or America, so I don't plan on adding any other languages.

Antechinus

The $txt strings are only used to make translation into multiple languages feasible.

Current action only affects if the tab highlights when that action (or a sub action under it) is selected. This can be a bit of a nuisance to set up if you aren't used to it but we're here to help.

LC

Quote from: Antechinus on September 25, 2009, 07:22:07 PM
The $txt strings are only used to make translation into multiple languages feasible.

Current action only affects if the tab highlights when that action (or a sub action under it) is selected. This can be a bit of a nuisance to set up if you aren't used to it but we're here to help.
Yes, the tabs highlight when used. So I guess I still need to add the current action part of it.

Here's what I am guessing it should look like when done?

Thanks for all the help as well.
// Show the [profilehelp] button.
     echo '<li', $current_action == 'Profilehelp' ? ' class="chosen"' : '', '>
     <a href="', $scripturl, '?action=Profilehelp"><span>Profile Help</span>


Antechinus

You have to close the list item and the anchor tag. If the next tab starts with a comment or echo you also need an apostrophe followed by a semi colon at the end of the tab code.

// Show the [profilehelp] button.
     echo '<li', $current_action == 'Profilehelp' ? ' class="chosen"' : '', '>
     <a href="', $scripturl, '?action=Profilehelp"><span>Profile Help</span></a></li>';

LC

Quote from: Antechinus on September 25, 2009, 07:40:41 PM
You have to close the list item and the anchor tag. If the next tab starts with a comment or echo you also need an apostrophe followed by a semi colon at the end of the tab code.

// Show the [profilehelp] button.
     echo '<li', $current_action == 'Profilehelp' ? ' class="chosen"' : '', '>
     <a href="', $scripturl, '?action=Profilehelp"><span>Profile Help</span></a></li>';

Ah I see what you did there..

Makes sense since HTML is the same way, somewhat. I was wondering why it looked incomplete to me.
Since I started the <li> and <a> it needed the ending tags and of course the end of the string semi colon. Der.

This is cool. I like learning this stuff. I appreciate the time you and mashby have taken with helping me.
Once it's broken down bit by bit I can grasp the concept better.

Thank you.

Advertisement: