Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: azasmith - marraskuu 13, 2013, 12:56:59 IP

Otsikko: Question regarding "active" tabs in Nav
Kirjoitti: azasmith - marraskuu 13, 2013, 12:56:59 IP
Hi guys, I've done a fair bit of searching, but nothing really matches what I'm looking for.

I've created two new tabs in my navigation, however when those pages are active, the active tab is still "Home".

I looked in subs.php for the part that dictates the "active" tabs, but what I've linked to isn't an action.

My links are to two boards. So the URLs I've linked are index.php?board=2.0 and index.php?board=3.0

Any ideas?
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: Arantor - marraskuu 13, 2013, 12:59:17 IP
Yeah, there's no really good way to make them active without modifying the menu code, because it's not really designed for that.

The active tab is designated by an action, i.e. action=profile or action=admin, except boards aren't actions and thus cannot be normally highlighted.

What code, exactly, did you add? We'll see if we can't make the right changes for you.
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: azasmith - marraskuu 13, 2013, 01:06:19 IP
In subs.php in between Home & Help

'Board' => array(
                'title' => 'The Board',
                'href' => '/forum/index.php?board=2.0',
                'show' => true,
                'sub_buttons' => array(
                ),
            ),
            'Grid' => array(
                'title' => 'The Grid',
                'href' => '/forum/index.php?board=3.0',
                'show' => true,
                'sub_buttons' => array(
                    'Mixes' => array(
                        'title' => 'Mixes',
                        'href' => '/forum/index.php?board=4.0',
                        'show' => true,
                    ),
                    'Releases' => array(
                        'title' => 'Releases/Tracks',
                        'href' => '/forum/index.php?board=5.0',
                        'show' => true,
                    ),
                ),
            ),


Removed the URLs, but you get the idea. I have noticed that when I got to Quote an existing thread, the action becomes post, which does set Board to active. But it also does this when I'm in Grid as well. So that's not right.

Thanks.
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: Arantor - marraskuu 13, 2013, 01:13:09 IP
There is absolutely no reason for either of those to become active under any circumstances unless for some strange reason you declared index.php?action=Board or index.php?action=Grid, not even if you removed the Home button...

Makes me wonder if you changed anything else as well...
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: azasmith - marraskuu 13, 2013, 01:59:02 IP
Lainaus käyttäjältä: Arantor - marraskuu 13, 2013, 01:13:09 IP
There is absolutely no reason for either of those to become active under any circumstances unless for some strange reason you declared index.php?action=Board or index.php?action=Grid, not even if you removed the Home button...

Makes me wonder if you changed anything else as well...

Are you always this patronising? I followed a thread on here to make these changes and afterwards found out that only "actions" get set as active. I'm very sorry that my php skills don't match yours, but I was asking a question, this is what the forums are for.

http://www.simplemachines.org/community/index.php?topic=261880.0  -  If you disagree with this advice, why is it on the forum. And easily found using Google.
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: All Colours Sam - marraskuu 13, 2013, 02:07:07 IP
@azasmith From what I understand you want to add a button (or buttons) that will link to a specific board, am I correct?

If that is what you want then the active tab would be the "home" one or "forum" if you use a portal. You can see the same behavior here on this site, go to any board or any topic, the active button will always be the "home" one.  Thats why I suggest you to leave the button as it is and left the home button to be the active one.
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: azasmith - marraskuu 13, 2013, 02:35:34 IP
Lainaus käyttäjältä: Suki - marraskuu 13, 2013, 02:07:07 IP
@azasmith From what I understand you want to add a button (or buttons) that will link to a specific board, am I correct?

If that is what you want then the active tab would be the "home" one or "forum" if you use a portal. You can see the same behavior here on this site, go to any board or any topic, the active button will always be the "home" one.  Thats why I suggest you to leave the button as it is and left the home button to be the active one.

Hi Suki,

Yeah that's correct, basically I only have two boards, but numerous child boards, so my thinking was to have "quick links" in the navigation to each place.

Thought from reading the thread that I posted above that it would also be possible to amend the active links, not to worry.
Thanks.

Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: emanuele - marraskuu 13, 2013, 02:40:36 IP
Since you are already editing the code, azasmith, you can just add:

elseif (!empty($board) && $board == 2)
$current_action = 'Board';
elseif (!empty($board) && in_array($board, array(3, 4, 5)))
$current_action = 'Grid';

after:
$current_action = 'moderate';
and of course:
global $board;
somewhere at the beginning of the function.

I'd suggest you to also change all the:
'href' => '/forum/index.php?board=4.0',
to something like:
'href' => $scripturl . '?board=4.0',
Otsikko: Re: Question regarding "active" tabs in Nav
Kirjoitti: azasmith - marraskuu 13, 2013, 02:55:00 IP
Lainaus käyttäjältä: emanuele - marraskuu 13, 2013, 02:40:36 IP
Since you are already editing the code, azasmith, you can just add:

elseif (!empty($board) && $board == 2)
$current_action = 'Board';
elseif (!empty($board) && in_array($board, array(3, 4, 5)))
$current_action = 'Grid';

after:
$current_action = 'moderate';
and of course:
global $board;
somewhere at the beginning of the function.

I'd suggest you to also change all the:
'href' => '/forum/index.php?board=4.0',
to something like:
'href' => $scripturl . '?board=4.0',

A million internets to you. Thanks Emanuele, works brilliantly.