tags:

views:

341

answers:

5

So I have a menu in a php file that looks like this (This is the whole file. I'm totally new to PHP.)

menu.php:

<li id="current"><a href="#"><span>Home</span></a></li> 
<li><a href="http://blog.me.net/"&gt;&lt;span&gt;Blog&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li><a href="http://www.me.net/R"&gt;&lt;span&gt;Results&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li><a href="http://www.me.net/P"&gt;&lt;span&gt;Pictures&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li><a href="http://www.me.net/O.html"&gt;&lt;span&gt;Our Location</span></a></li>

Now in my pages I do this (index.php):

<div id="tabs1" >
    <ul>
        <!-- CSS Tabs -->
        <?php include("menu.php"); ?>
    </ul>
</div>

So what I want to be able to do is change the line above to this:

<?php include("menu.php?current=pictures"); ?>

Which would make the active tab the Pictures tab. How can I do this?

A: 

Try this:

<li <?php if($_GET['current'] == 'home') {echo 'id="current"'}?>><a href="#"><span>Home</span></a></li> 
<li <?php if($_GET['current'] == 'blog') {echo 'id="current"'}?>><a href="http://blog.me.net/"&gt;&lt;span&gt;Blog&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li <?php if($_GET['current'] == 'results') {echo 'id="current"'}?>><a href="http://www.me.net/R"&gt;&lt;span&gt;Results&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/li&gt;
and so on....
Sarfraz
It's not working for some reason. I did it exactly like you said.
Bob Dylan
@Bob: is your current value coming from query string eg when you visit blog page, visit it like this blog.php?current=blog
Sarfraz
A: 

I don't think its necessary for it to be done at the server side (using up CPU cycles).

Use javascript/CSS to achieve this.

Sairam Kunala
+2  A: 

You could also try this:

Your php script

<?php
    $selected = "pictures";
    $current_id = ' id="current"';
    include "menu.php";
?>

this is your menu:

<ul>
<li <?php if ($selected == "pictures") print $current_id; ?>><a href="#"><span>Home</span></a></li> 
<li <?php if ($selected == "blog") print $current_id; ?>><a href="http://blog.me.net/"&gt;&lt;span&gt;Blog&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li <?php if ($selected == "home") print $current_id; ?>><a href="http://www.me.net/R"&gt;&lt;span&gt;Results&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li <?php if ($selected == "me") print $current_id; ?>><a href="http://www.me.net/P"&gt;&lt;span&gt;Pictures&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; 
<li <?php if ($selected == "contacts") print $current_id; ?>><a href="http://www.me.net/O.html"&gt;&lt;span&gt;Our Location</span></a></li>
</ul>
Vittorio Vittori
A: 

This is very basic stuff. You should look into using a framework that already includes all the basic stuff like this.

Examples of frameworks are CakePHP and Code Igniter.

I would personaly use an MVC (model view controller) style framework.

Then in your view you could:

<?php echo Tag('li')->class('current', URL::is_current('http://blog.me.net/'))-&gt;href('http://blog.me.net/')-&gt;html('Blog'); ?>
Petah
A: 

worth looking at

intelligent navigation

pixeltocode