Jump to content

php include sub navigation selected


jasonhr13

Recommended Posts

ok so here is my issue. I have a navigation that is in top-nav.php and i want it the links to show as selected when im on the page for them. I use an if statement and this works for all the top level links. But when im on a page that is a sub menu(drop down item) of one of the main links i want that main link to show as selected....

 

for instance i have this below.. as you can see the second main link has a sub navigation. each php file has a $current_page = "pageName" in them. But when I do it this way which to me theoretically should work, it always stayed selected no matter what page in on....

 

for reference... http://a120900.sb1.dev.codeanywhere.net/thwebco/index.php

 

<ul id="nav" class="sf-menu">
   <li class="<?php if($current_page == 'home') echo "current-menu-item";?>"><a href="index.php">Home<span class="subheader">Welcome</span></a></li>
   <li class="<?php if($current_page == 'development' || 'seo' || 'mobile' || 'social' || 'hosting') echo "current-menu-item";?>"><a href="#">Services<span class="subheader">What we offer</span></a>
    <ul>
	 <li><a href="development.php"><span> Web Design & Development</span></a></li>
	 <li><a href="seo.php"><span> Search Engine Optimization </span></a></li>
	 <li><a href="mobile.php"><span> Mobile </span></a></li>
	 <li><a href="social.php"><span> Social Media </span></a></li>
                                   <li><a href="hosting.php"><span> Web Hosting & Email </span></a></li>
    </ul>
   </li>

   <li><a href="#">Our Work <span class="subheader">See our work</span></a>
                           <ul>
                                   <li class="<?php if($current_page == 'portfolio') echo "current-menu-item";?>"><a href="portfolio.php"><span>Portfolio </span></a></li>
                                   <li class="<?php if($current_page == 'case') echo "current-menu-item";?>"><a href="case.php"><span>Case Studies </span></a></li>
                                   </ul>
                                   </li>
   <li class="<?php if($current_page == 'about') echo "current-menu-item";?>"><a href="about.php">About Us<span class="subheader">Who we are</span></a>

   </li>
   <li class="<?php if($current_page == 'contact') echo "current-menu-item";?>"><a href="contact.php">Contact<span class="subheader">Get in touch</span></a></li>
                           <li class="<?php if($current_page == 'quote') echo "current-menu-item";?>"><a href="quote.php">Get A Quote<span class="subheader">Let us help</span></a></li>
  </ul>

Link to comment
Share on other sites

I've done this a couple of times with websites that I've built. The way I did it is in my database, I had flags which were set if a menu item was a top level link. Then for each of the sub-menu links, I had a field that said which of the top level links was its parent. That way I could match both the current link, and the parent link, from one field in the database, hence being able to highlight both the submenu link and the top level link.

 

I'm not sure how your data is stored, but you could try adapting that idea to your application.

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.