sparrow3274 Posted December 15, 2006 Share Posted December 15, 2006 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 :DThis 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 --- Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/ Share on other sites More sharing options...
sanfly Posted December 16, 2006 Share Posted December 16, 2006 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 senseAlso, you have no space between <li and $tab1 etc, and the tab variables are not in php tagsAnyway, 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] Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142109 Share on other sites More sharing options...
sparrow3274 Posted December 16, 2006 Author Share Posted December 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142128 Share on other sites More sharing options...
sparrow3274 Posted December 16, 2006 Author Share Posted December 16, 2006 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] Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142176 Share on other sites More sharing options...
sparrow3274 Posted December 16, 2006 Author Share Posted December 16, 2006 anyone have any thoughts on this? ... please ;D Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142213 Share on other sites More sharing options...
sanfly Posted December 16, 2006 Share Posted December 16, 2006 this/family/?page_id=4doesnt look like a valid url to me. normally is something like/family/somepage.php?page_id=4Regarding 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 Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142216 Share on other sites More sharing options...
sparrow3274 Posted December 16, 2006 Author Share Posted December 16, 2006 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! Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142228 Share on other sites More sharing options...
sanfly Posted December 16, 2006 Share Posted December 16, 2006 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 worksIs 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? Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142265 Share on other sites More sharing options...
sparrow3274 Posted December 16, 2006 Author Share Posted December 16, 2006 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... Link to comment https://forums.phpfreaks.com/topic/30816-php-and-unordered-list-navigation-menu-include/#findComment-142460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.