News:

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

Main Menu

Getting current_action = homepage

Started by MLM, December 23, 2010, 08:09:54 PM

Previous topic - Next topic

MLM

I have added a homepage tab to my nav bar but can not get it highlighted / current class.

My Homepage is here: http://www.example.com/
My Forums are here: http://www.example.com/forums/

As you can see the current_action is "homepage"

To start off i have the subs.php and index.template.php file as this:
$current_action = 'forums';

The current tab is selected like this:
<li class="' , $current_action == 'homepage' ? 'current' : '' , '">


In Subs.php I have added an elseif underneath current_action or whatever:
current_action:

if (isset($context['menu_buttons'][$context['current_action']]))
$current_action = $context['current_action'];


elseif:
elseif ($context['current_action'] == 'homepage')
$current_action = 'homepage';


I understand I am supposed to add it to the index.php action array but i do not want it ?homepage etc.

I have tried putting the text below in the index.php
define('homePage', 1);

and then adding this to subs.php: --- But nothing happened
    if (defined(homePage))
    $current_action = 'homepage';



So basically i need it to recognize http://www.example.com/ as a action and set the current_action to homepage

This site has their homepage like how i want it but i cant view the subs.php, etc of the site...

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Matthew K.

Well first of all, the Subs.php edit you have with the definition should be
    if (defined('homePage'))
    $current_action = 'homepage';

MLM

Quote from: Labradoodle-360 on December 23, 2010, 08:32:48 PM
Well first of all, the Subs.php edit you have with the definition should be
    if (defined('homePage'))
    $current_action = 'homepage';


Still no effect..

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Kays

I'm assuming that this is for SMF 2.0

If your tab is called 'homepage' then on your home page before SSI.php is included add the following:


$_GET['action'] = 'homepage';


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Matthew K.

Kays - He's not wanting to put ?action= in the URL, so I was assuming having something defined in the homepage was the only other way that's easy.

Kays

Maybe not. But that's the way it works for 2.0.

Subs.php:

Code (setupThemeContext) Select

$context['current_action'] = isset($_GET['action']) ? $_GET['action'] : '';


Code (setupMenuContext) Select

if (isset($context['menu_buttons'][$context['current_action']]))
$current_action = $context['current_action'];


A bit of a side benefit to defining $_GET[,action'] is that by adding a line to the who.{language}.php you can also get the user to display in the who's online list.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

MLM

Alright so now i am a little confused. What should i try?

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Kays

Which version SMF are you using? If it is 2.0 try what I suggested.

If it's 1.x, then it can be done differently.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Matthew K.

Kays - But that's inside SMF, if an action is SET. He wants to use SSI for a homepage, and have it NOT be an action, yet be an active tab. So some data has to be questioned to determine whether they're on the homepage or not, but it can't be $_GET['action'] or even $_REQUEST['action'] because it's there's nothing set in the URL for "action".

MLM

Quote from: Labradoodle-360 on December 23, 2010, 11:40:25 PM
Kays - But that's inside SMF, if an action is SET. He wants to use SSI for a homepage, and have it NOT be an action, yet be an active tab. So some data has to be questioned to determine whether they're on the homepage or not, but it can't be $_GET['action'] or even $_REQUEST['action'] because it's there's nothing set in the URL for "action".

^ he's right

2.0 RC4

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Kays

It works for SSI.php also and you don't need to make any additional coding changes.

Somehow you need to carry a value for the page someone is on. For 1.x I think you used to be able to use $context[/current_action. With 2.0 that don't work and the only way I could find to do it was to set $_GET['action']. The code is setup to to accept it and display the button as active.

Also, the $_GET['action'] isn't shown in the url nor does it need to be in the url. Just add that line on your home page before SSI.php is included.

Edit:
You shouldn't need to edit index.template.php at all. How did you add the button?


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Matthew K.

$_GET['action'] looks for "action=" in the URL. If there is no action=something in the URL, it will return nothing. And $context['current_action'] is a valid variable in 2.0.

Kays

Have you tried it. I wouldn't of posted it if it didn't work.

As stated previously, there's the added advantage of showing who's viewing that page. A method I've been using for years on a variety of pages on my site. $_GET['action'] can be set to anything after the page is loaded and it doesn't mess things up.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

MLM

THANK GOD WE HAVE KAYSO:)

Worked like a charm! - Sorry for doubts, I have been working with Labradoodle-360 almost all day.
$_GET['action'] = 'homepage';


I had to edit my index.templay.php because I have a wierd nav bar but it all sorta makes sense lol - very cool: if you want to check it out just aim me.

Thanks Kays and good night. Case Closed  ;D

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Kays

Cool, it is a bit too simple isn't it. :)

As I stated earlier you also now see how's viewing that page in the who's online list. To do that on your home page after SSI.php is included add the following.


writeLog();


Then in Who.{language}.php for the language you are using add the following line before the closing ?>


$txt['whoall_homepage'] = 'Viewing the "Home" page.';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

MLM

Alright - I do not think i will need this for the homepage but will definataly come in handy in the future. Page is faved...

I want to stop bumping this since main prob is solved and i am about to post another issue i am dealing with.

Thanks for all the help :)

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Advertisement: