Jump to content

php and unordered list navigation menu include


sparrow3274

Recommended Posts

Hello,

I was wondering if someone could help me out... I am making a navigation menu using css and unordered lists, the list is inside an include file and I have set up the list/tabs/buttons so it has 3 states (default, hover, and active) I am trying to have the code read the page_id(file name) and then have it generate id=current in the list... like <li id=current> but I keep getting all kinds of errors.... I can't put anything on the pages specifically because they are generated, so it has to go in the include...

Here's what i've messed up so far :D

This is in the top:

[b]Php Code:[/b]
[color=red]<?php
        if(!$_GET('page_id')) { $tab1 = 'id="current"'; }
        if(!$_GET('page_id') == 3) { $tab2 = 'id="current"'; }
        if(!$_GET('page_id') == 4 ) { $tab3 = 'id="current"'; } 
?> [/color]


and here is my list navigation:

[b]Html Code: [/b]
[color=green]<div id="navwrapper">
    <ul id="nav">
      <li$tab1><a href="<?php echo get_settings('home'); ?>/"><span>Home</span></a></li>
      <li$tab2><a href="<?php echo get_settings('home'); ?>/Calendar/"><span>Calendar</span></a></li>
      <li$tab3><a href="<?php echo get_settings('home'); ?>/?page_id=4"><span>Phonebook</span></a></li>
      <li$tab4><a href="<?php echo get_settings('home'); ?>/Links/"><span>Links</span></a></li>
      <li$tab5><a href="<?php echo get_settings('home'); ?>/Contact/"><span>Contact</span></a></li>
      </ul>
  </div> [/color]

does anyone know why this wouldn't work, or if there is a better way?
Thank you for any help you can provide
---
I see a couple of things that dont make sense to me here.

[code=php:0]<?php
        if(!$_GET('page_id')) { $tab1 = 'id="current"'; }
        if(!$_GET('page_id') == 3) { $tab2 = 'id="current"'; }
        if(!$_GET('page_id') == 4 ) { $tab3 = 'id="current"'; }
?> [/code]

what exactly are you trying to do here? I think it should be more like

[code=php:0]<?php
        if(!$_GET['page_id']) { $tab1 = 'id="current"'; }
        if($_GET['page_id'] == 3) { $tab2 = 'id="current"'; }
        if($_GET['page_id'] == 4 ) { $tab3 = 'id="current"'; }
?> [/code]

Note the use of square brackets, not regular brackets,and also you had ! infront of all your $_GET which doesnt make sense

Also, you have no space between <li and $tab1 etc, and the tab variables are not in php tags

Anyway, I would say something like this would be better

[code=php:0]<div id="navwrapper">
    <ul id="nav">
      <li <?php if(!GET['page_id']) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/"><span>Home</span>[/url]</li>
      <li <?php if(GET['page_id'] == 3) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/Calendar/"><span>Calendar</span>[/url]</li>
      <li <?php if(GET['page_id'] == 4) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/?page_id=4"><span>Phonebook</span>[/url]</li>
      <li><a href="<?php echo get_settings('home'); ?>/Links/"><span>Links</span>[/url]</li>
      <li><a href="<?php echo get_settings('home'); ?>/Contact/"><span>Contact</span>[/url]</li>
      </ul>
  </div>
[/code]
I had just fixed the bracket thing and that stopped it from completely blowing up... also I tried what you did in the list but that didn't work? I noticed that your list doesn't have $tab1 in the php <li>

I am to have the <li> recognize what page it is on and display a different background.... just making it highlight for the current page the user is on. I can do this in most things but this <li> structure is inside of a include and it is a bit tricker....

Thanks for help and suggestions
I have made some progress... it will highlight the first tab with this code, however when i click on one of the other tabs and it goes to that page the tab does not stay on???

[b]top php:[/b]

[color=red]<?php
if(!$_GET['page_id']) { $tab1 = 'id="current"'; }
if(!$_GET['page_id'] = 3) { $tab2 = 'id="current"'; }
if(!$_GET['page_id'] = 4 ) { $tab3 = 'id="current"'; } 
?>[/color]

the end of the url for the first one looks like /family/  ---no page name and the correct tab highlights --

the end of the url for the third one looks like /family/?page_id=4  ---no tab is highlighted --

[b]list:[/b]

[color=green]<div id="navwrapper">
  <ul id="nav">
    <li <?php  echo "$tab1";  ?>><a href="<?php echo get_settings('home'); ?>/"><span>Home</span></a></li>
    <li <?php  echo "$tab2"; ?>><><a href="<?php echo get_settings('home'); ?>/Calendar/"><span>Calendar</span></a></li>
    <li <?php  echo "$tab3"; ?>><a href="<?php echo get_settings('home'); ?>/?page_id=4"><span>Phonebook</span></a></li>[/color]
this

/family/?page_id=4

doesnt look like a valid url to me.  normally is something like

/family/somepage.php?page_id=4

Regarding your comment above, if you use this

[code=php:0]<div id="navwrapper">
    <ul id="nav">
      <li <?php if(!GET['page_id']) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/"><span>Home</span>[/url]</li>
      <li <?php if(GET['page_id'] == 3) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/Calendar/"><span>Calendar</span>[/url]</li>
      <li <?php if(GET['page_id'] == 4) { echo "id=current"; } ?>><a href="<?php echo get_settings('home'); ?>/?page_id=4"><span>Phonebook</span>[/url]</li>
      <li><a href="<?php echo get_settings('home'); ?>/Links/"><span>Links</span>[/url]</li>
      <li><a href="<?php echo get_settings('home'); ?>/Contact/"><span>Contact</span>[/url]</li>
      </ul>
  </div> [/code]


you dont need this

[code=php:0]<?php
        if(!$_GET['page_id']) { $tab1 = 'id="current"'; }
        if($_GET['page_id'] == 3) { $tab2 = 'id="current"'; }
        if($_GET['page_id'] == 4 ) { $tab3 = 'id="current"'; }
?> [/code]


so you dont need the $tab, basically does it inline
hello,

I tried what you suggested... with the inline only and it busted the page... I can get the first tab(home) to work, but none of the others... it is a weird url... it's a wordpress backend... and it's the only thing that shows up.. the one that work shows up http://www.yoururl.com/family/ just like that when i press another tab the url looks like this http://www.yoururl.com/family/?page_id=4 ... i am assuming it stores it in the database?  I can't find a page or anything on the server... thanks for your help!
Be more specific when you say "Busted the page".  Exactly what is happening?  Are you getting any error messages?

EDIT, actually looking at the inline code, I see i missed the $_ from infront of each of the GET[].  Put them in and see if that works

Is this a script that you have written?

Does this link http://www.yoururl.com/family/?page_id=4 actually go anywhere? 

Are you using mod rewrite for your urls?
THANK YOU! .... it worked! ...no it(the code) was something that my friend wrote me in a hurry, he was really busy and couldn't figure out what was going... so i kept messing with it and came here... thanks for your help... it's a present to my family...

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.