Forum Moderators: coopster

Message Too Old, No Replies

Rewriting a function

pass id to hightlight current page on the nav menu

         

mperez5

8:34 pm on Apr 19, 2007 (gmt 0)

10+ Year Member



Hi All,
I am trying to pass my id before calling "include(get(id), pass)" but I do not know how, does anyone can give me some suggestions, please?

<style type="text/css">
ul { list-style-type: none; margin: 0.5em 0 0 0px; padding: 0; position: relative; overflow: visible; height: auto; }
ul li { height: 2.0em; width: 200px; }
ul li a, ul li a:visited { width: 200px; height: 2.0em; display: block; color: #999; text-decoration: none; background: #525252; margin: 0.8em 0 0 0; text-indent: 10px; }
ul li a:hover { display: block; background: #eee; color: #333; }
ul li a.currentpage, ul li a.currentpage:visited { background: #FF7F50; color: #000; }
</style>
<?php
ob_start();

$pass = array('home','news');
if (in_array($_GET['id'], $pass)) {
//include('http://www.mysite.com/nav.php?page='.$_GET['id']);
include ($_GET['id'] . '.php');
}
include('nav.php');

scriptmasterdel

9:53 pm on Apr 19, 2007 (gmt 0)

10+ Year Member



Hi,

I am not sure 100% what you mean.

If you declare a variable it will be parsed throughout all files included. e.g.

$pass = array('home','news');
if (in_array($_GET['id'], $pass)) {
//include('http://www.mysite.com/nav.php?page='.$_GET['id']);
include ($_GET['id'] . '.php');
}

Now, $pass is accessible from the "$_GET['id'] . '.php'" file, if that makes any sense?

Please could you supply us with a little more information on what you are trying to achieve?

Thanks

Del

mperez5

10:42 pm on Apr 19, 2007 (gmt 0)

10+ Year Member



I just trying to rewrite this function. In the array are the pages of my site.
When I click the nav menu goes to home or news page and the menu gets hightlighted.
The function below works fine but the output goes on top of the menu which I don't want.

$pass = array('home','news');
if (in_array($_GET['id'], $pass)) {
include ($_GET['id'] . '.php');
}
include('nav.php');

I was thinking to rewrite it this way so the output be below the nav menu hightlighting the current page.

$pass = array('home','news');
if (in_array($_GET['id'], $pass)) {
include('http://www.mysite.com/main.php?page='.$_GET['id']);
include('nav.php');
include ($_GET['id'] . '.php');
}


Let me know if should I provide the other three pages with 3 lines of code. Also thanks for your help

scriptmasterdel

10:01 pm on Apr 23, 2007 (gmt 0)

10+ Year Member



Can you not just recall the in_array function more then once, and set the pass array above all other content

$pass = array('home','news');

// inside nav.php - check if (in_array($_GET['id'], $pass))
include('nav.php');

if (in_array($_GET['id'], $pass)) {
include('http://www.mysite.com/main.php?page='.$_GET['id']);
include ($_GET['id'] . '.php');
}

Am i on the right lines?

Thanks for listening ...

mperez5

6:10 pm on Apr 24, 2007 (gmt 0)

10+ Year Member



Hi scriptmasterdel,
Thanks for looking at my code but it doesn't work.

$pass = array('home','news');
if (in_array($_GET['id'], $pass)) {
include('nav.php');
if (in_array($_GET['id'], $pass)) {
include ($_GET['id'] . '.php');
}
}

The menu does not get highlight it.