Advertisement:

Author Topic: Custom menu not being detected as current action  (Read 4093 times)

Offline xiuide

  • Newbie
  • *
  • Posts: 7
Custom menu not being detected as current action
« on: April 23, 2008, 09:32:22 PM »
Im not sure if this is a bug, or my stupidity, so, im posting here first.

I am working on an intergrated website solution using SMF using SSI.php and the related php calls (including template functions from the theme(s)) I edited the menu items a bit, chaing home to forums (as well as adding a new constant for it), and adding a new "home" menu item as shown below:
Code: [Select]
$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => 'http://www.mysite.us',
'show' => true,
'sub_buttons' => array(
),
),
'forum' => array(
'title' => $txt['forum'],
'href' => $scripturl,
'show' => true,
'sub_buttons' => array(
),
),

I then changed $current_action = 'home'; to $current_action = 'forum';

the menu works exactly as you would expect, except that it seems that the software is not detecting that "home" is the active page the user is visiting, as in, when you hover over the home link, you will get the hover color, but, once you click on it, it shows the "forum" tab as the active page. i have tested this on several 2.0b3 compatable themes (overview, blackrain... ect.)

you can see what im talking about at hxxp:www.thegodsofwar.us [nonactive]

if anyone could shed some insight that would be great, and also, if this has been posted before, im sorry. i searched, but didnt find anything to this problem.

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Custom menu not being detected as current action
« Reply #1 on: April 23, 2008, 10:57:00 PM »
I called the menu item 'front' and added this at the button of that function in Subs.php

Code: [Select]
// Check if on the front page
if ($_SERVER['SCRIPT_NAME'] == '/index.php')
$current_action = 'front';
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline xiuide

  • Newbie
  • *
  • Posts: 7
Re: Custom menu not being detected as current action
« Reply #2 on: April 23, 2008, 11:14:11 PM »
that would work if I was making a call to a page in my forum directory, but, im not :-/ I spose I should have specified that, sorry, my server setup is like this

mysite.com/index.php
forums.mysite.com/index.php (mysite.com/forums  ...they are both the same thing)

so what happens is that the script detects index.php from forums.mysite.com and instead of the forum tab showing active, it shows the home tab active (when im on the fourm), complete reversal of what origionally happens, but, like I said, this tip will come in handy for when/if I add pages directly into the forum directory
« Last Edit: April 23, 2008, 11:17:09 PM by xiuide »

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Custom menu not being detected as current action
« Reply #3 on: April 23, 2008, 11:22:35 PM »
Have a look at the site in my sig. Mine is setup

thereptilefile.com/index.php as the front page
thereptilefile.com/forum/index.php as the forum

That code works for my menu. The SCRIPT_NAME is the part after the domain name. So when on the SSI page it sees /index.php and on the forum page it sees /forum/index.php
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline xiuide

  • Newbie
  • *
  • Posts: 7
Re: Custom menu not being detected as current action
« Reply #4 on: April 23, 2008, 11:30:38 PM »
hmm ok, maybe i missunderstood where to put that bit of code from you... i have it placed right before $current_action='forum' so...

Code: [Select]
if ($_SERVER['SCRIPT_NAME'] == '/index.php')
$current_action = 'front';
else{
$current_action = 'forum';
};

if im wrong, then girr to me for not totally understanding what you said in the first post >.<

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Custom menu not being detected as current action
« Reply #5 on: April 23, 2008, 11:32:45 PM »
It needs to go in the button of the Subs.php file where you added in the menu item. Here's a section of the code

Code: [Select]
// Figure out which action we are doing so we can set the active tab.
// Default to home.
$current_action = 'home';

if (isset($context['menu_buttons'][$context['current_action']]))
$current_action = $context['current_action'];
elseif ($context['current_action'] == 'search2')
$current_action = 'search';
elseif ($context['current_action'] == 'theme')
$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';

// Check if on the front page
if ($_SERVER['SCRIPT_NAME'] == '/index.php')
$current_action = 'front';
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline SleePy

  • Site Team Lead
  • SMF Master
  • *
  • Posts: 30,371
  • Gender: Male
  • Thats his happy face.
    • jdarwood007 on GitHub
    • @jdarwood on Twitter
    • SleePy Code - My personal site
Re: Custom menu not being detected as current action
« Reply #6 on: April 23, 2008, 11:40:51 PM »
Code: [Select]
if ($_SERVER['SCRIPT_NAME'] == '/index.php')
That may not work because he uses a sub domain.

Doing something like
Code: [Select]
if (SMF == 'SSI')would be better as it would only run if you where using SMF through SSI.
Jeremy D — Site Team / SMF Developer
Support the SMF Support team!
Profiles:
GitHub

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Custom menu not being detected as current action
« Reply #7 on: April 23, 2008, 11:45:15 PM »
True I just wasn't sure if he wanted all his SSI pages to register as home. You could do a combination of the two if you only want the home SSI page to register and not other SSI pages.

Code: [Select]
if (SMF == 'SSI' && $_SERVER['SCRIPT_NAME'] == '/index.php')
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline xiuide

  • Newbie
  • *
  • Posts: 7
Re: Custom menu not being detected as current action
« Reply #8 on: April 23, 2008, 11:48:49 PM »
Code: [Select]
if(SMF == 'SSI) seemed to work out great, so thanks for that, however, for some odd reason, when i tried to use
Code: [Select]
if ($_SERVER['SCRIPT_NAME'] == '/index.php') where you had put it, rsw686 it still was not working, but, the imidate fix is done, and its what i needed (for now at least) and I can tinker with the other code and see if i can get it working at another date, thanks both of you for your help

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Custom menu not being detected as current action
« Reply #9 on: May 20, 2008, 07:28:55 AM »
Hello xiuide, have you made any further progress, or is the case solved? I just want to make sure. :)
    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting