tags:

views:

325

answers:

1

Hello everyone, looking for some help:)

http://69.65.3.168/~doubleop/pro.sperity/blog

is the site i am working on, you can see the navigation is a drop down. I want the green to hover over active pages.

This is a drop down menu, so i created parent pages as the main nav links, and the drop down contains child pages.

All the links are hard coded at the moment, not using wordpress' built in function.

This is my code for the active links, which works well on normal .php sites, but not on wordpress

    <ul id="menu">
    <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'index') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?>><a href="http://69.65.3.168/~doubleop/pro.sperity/"&gt;Home&lt;/a&gt;
<!--No drop downs-->
    </li>
    <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'blog') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/blog"&gt;Blog&lt;/a&gt;
<!--No drop downs-->
    </li>
    <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'business-model') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model"&gt;Business Model</a>
     <ul>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/introduction"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/investment-strategy"&gt;Investment Strategy</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/investor-benefits"&gt;Investor Benefits</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/investment-programs"&gt;Investment Programs</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/properity-partnership"&gt;Prosperity Partnership</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/rrsp-investment"&gt;RRSP Investment</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/limited-partnership"&gt;Limited Partnership</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/refferal-program"&gt;Refferal Program</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/business-model/faq"&gt;FAQ&lt;/a&gt;&lt;/li&gt;
     </ul>
    </li>
     <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'track-record') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/track-record"&gt;Tack Record</a>
     <ul>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/track-record/company-overview"&gt;Company Overview</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/track-record/investment-portfolio"&gt;Investment Portfolio</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/track-record/why-prosperity"&gt;Why Prosperity</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/track-record/testimonials"&gt;Testimonials&lt;/a&gt;&lt;/li&gt;
     </ul>
    </li>
     <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'current-oppertunities') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/current-oppertunities"&gt;Current Oppertunities</a>
     <ul>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/current-oppertunities/current-offerings"&gt;Current Offerings</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/current-oppertunities/ivestor-interest-form"&gt;Investor Interest Form</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/current-oppertunities/properties-for-rent"&gt;Properties for Rent</a></li>
     </ul>
    </li>
     <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'upcoming-events') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/upcoming-events-news"&gt;Upcoming Events &amp; News</a>
    </li>
     <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'mentorship-program') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/mentorship-program"&gt;Mentorship Program</a>
    </li>
     <li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'about-us') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> ><a href="http://69.65.3.168/~doubleop/pro.sperity/about-us"&gt;About us</a>
     <ul>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/about-us/mission-statement"&gt;Mission Statement</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/about-us/management-team"&gt;Management Team</a></li>
      <li><a href="http://69.65.3.168/~doubleop/pro.sperity/about-us/contact"&gt;Contact&lt;/a&gt;&lt;/li&gt;
     </ul>
</ul>

(the code is showing up wierdly, but you get the idea)

I tried echoing out the script_filename, and it was index.php on every page.

Anyone know how i can go about doing this? I need the active state to stay there when the user is on the relevant page, or any relevant child pages within under the parent

Thank you

+1  A: 

$_SERVER['SCRIPT_FILENAME'] is the same on every page since Wordpress directs all pages to the same script for processing.

If you want to search the URI for a specific string, try using $_SERVER['REQUEST_URI'] instead; that returns the requested URI, regardless of which script is being executed.

Also, in the code supplied, you misspelled "inactive" as "nactive."

Jakob
Hey thanks, that works greathttp://69.65.3.168/~doubleop/pro.sperity/business-modelBut it doesnt work on the child pages, even tho the name is still in the URL??
Hey got it figured out, didnt need basename, thanks for the help !!