jonnyo22 Posted September 26, 2009 Share Posted September 26, 2009 hi, tabs link colours, when one tab is selected the others are grey (#2c2c2c) but when no tabs are selected the home tab stays white so i need to know how i can say when no tabs are selected the link colour is #2c2c2c like the others when this is the case? heres the code that makes the others grey when not selected... // get link location options $linkOpt = explode(":", $pageLinksTop['location']); if ($linkOpt[0] == 1) { if ($catresult == $_GET['page']) { $box_content->assign("FONTSTYLE",'topNavOn'); $box_content->assign("LINKSTYLE",'topLinkOn'); } else { $box_content->assign("FONTSTYLE",'topNavOff" stlye="color#2c2c2c;'); $box_content->assign("LINKSTYLE",'topLinkOff" style="color:#2c2c2c;'); } if ($navOpt[7] == 1) { (i added the 'topNavOff' colour style to see if that would work but it didnt.) Quote Link to comment https://forums.phpfreaks.com/topic/175632-quick-how-to-question/ Share on other sites More sharing options...
sKunKbad Posted September 26, 2009 Share Posted September 26, 2009 This is the way I'm doing it. Perhaps you can adapt the code to meet your needs: <?php $horz = array( 'Home' => array( 'home', 'Brian\'s Web Design - Home Page' ), 'Web Portfolio +' => array( 'portfolio', 'Brian\'s Web Design - My Web Design Portfolio & More' ), 'Development' => array( 'development', 'Brian\'s Web Design - Development Projects' ), 'About' => array( 'about', 'Brian\'s Web Design - About Me' ), 'FAQs' => array( 'faq', 'Brian\'s Web Design - Frequently Asked Questions' ), 'Contact' => array( 'contact', 'Brian\'s Web Design - Contact Page' ), 'Get an Estimate' => array( 'estimates', 'Brian\'s Web Design - Submit a Web Design or Development Application' ), 'Templates' => array( 'templates', 'Brian\'s Web Design - Website Design Template Showcase' ) ); foreach ($horz as $key => $value){ static $y = 1; if ($y != 1) { echo "\t\t\t\t\t\t\t\t"; } // If home page and current if ($value[0] == 'home' && ! $this->uri->segment(1)) { echo "<li>" . html_entity_decode( anchor('',$key, array( 'class'=>'active','title'=>$value[1])), ENT_QUOTES) . "</li>\n"; } // If not home page, but current else if($value[0] == $this->uri->segment(1)) { echo "<li><a class=\"active\" href=\"". base_url() ."{$value[0]}.php\" title=\"{$value[1]}\">{$key}</a></li>\n"; } // If home page link and not the current page else if($value[0] != $this->uri->segment(1) && $value[0] == 'home') { echo "<li><a id=\"first-off\" href=\"". base_url() ."\" title=\"{$value[1]}\">{$key}</a></li>\n"; } // If external or other else { echo "<li><a href=\"{$value[0]}.php\" title=\"{$value[1]}\">{$key}</a></li>\n"; } $y++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175632-quick-how-to-question/#findComment-925450 Share on other sites More sharing options...
jonnyo22 Posted September 26, 2009 Author Share Posted September 26, 2009 Hi, thanks for your reply but unfortuantly my php knowledge is very limited and i wouldnt know how to adapt your could to suit, any pointers? Quote Link to comment https://forums.phpfreaks.com/topic/175632-quick-how-to-question/#findComment-925457 Share on other sites More sharing options...
sKunKbad Posted September 26, 2009 Share Posted September 26, 2009 You need to determine what page you are on at the time. My code is checking the URI segment through a class that is unique to the CodeIgniter framework, but you can parse the URI of your current page using php's built in function parse_url(). You'd use $_SERVER['PHP_SELF'] as the the string for the first parameter. It should then be obvious that as I am looping through and building my menu from the array, that I am checking the array values to see if the particular key corresponds to the link being built, and if it does, I insert the special class that applies to that link only. In my code, when the first link is "off", I apply a special ID for styling, but you will probably not need this. There are probably a few different ways to do this, but this is the way that works for me. I can't code it for you, or you'll never learn PHP. Play with the parse_url() function, and I'm sure you will see that what you are trying to do is quite easy. Quote Link to comment https://forums.phpfreaks.com/topic/175632-quick-how-to-question/#findComment-925568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.