Jump to content

[SOLVED] menu.php - I do not know a good subject


Lamez

Recommended Posts

Ok I post yesterday about my menu.php

 

I only want to edit one page when I add a menu item or when I move a page.

 

Ok so I asked if I could do a include like this

 

menu.php?page=index

 

because I added a selection code to my css so my menu would like this (in HTML)

 

  <div class="menu">
   <ul>		
<li class="selected"><a href="index.php">Home</a></li> [b]<-Selected: Indicates the user is on this page[/b]
<li class="nonselected"><a href="_login/_members/members.php">Members</a></li> [b]<-Not Selected: Indicates the user is not on the page[/b]
<li class="nonselected"><a href="login.php">Login</a></li>
<li class="nonselected"><a href="register.php">Register</a></li>
<li class="nonselected"><a href="info/info.php">Info</a></li>
   </ul>
  </div>

 

Well I got an error in my include when I did that

 

Warning: include(menu.php?page=login) [function.include]: failed to open stream: Invalid argument in C:\xampp\htdocs\JUNK\LAMEZ\login.php on line 56

 

Warning: include() [function.include]: Failed opening 'menu.php?page=login' for inclusion (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\JUNK\LAMEZ\login.php on line 56

 

So someone gave me this code

 

<div class="menu">
  <ul>		
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'index.php') ? 'selected' : 'nonselected'; ?>"><a href="index.php">Home</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'members.php') ? 'selected' : 'nonselected'; ?>"><a href="_login/_members/members.php">Members</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'login.php') ? 'selected' : 'nonselected'; ?>"><a href="login.php">Login</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'register.php') ? 'selected' : 'nonselected'; ?>"><a href="register.php">Register</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'info.php') ? 'selected' : 'nonselected'; ?>"><a href="info/info.php">Info</a>
  </ul>
</div>

 

Well it did not work, at all

 

Any Ideas?

 

Was I clear enough?

You can't pass query string parameters in an include.

 

Just set a variable in each page that menu.php will use to determine which link is "active".

 

For example, index.php:

<?php
$current_page = "home";

include_once "menu.php";
?>

 

menu.php

<div class="menu">
  <ul>		
    <li class="<?php echo ($current_page == 'home') ? 'selected' : 'nonselected'; ?>"><a href="index.php">Home</a></li>
  </ul>
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.