title: How to use PHP to display active class on sub nav links?
body: <p>I have PHP code to display the active class on links in the nav, but I'm having trouble finding a solution to applying the active class properly for the sub nav - that being the pages that are in folders outside of the root directory. Here is the code that I have!</p>
  
  <p>Here is the example code: (it works on the real code)</p>
  
  <pre><code>&lt;?php
      $current_page = basename($_SERVER['PHP_SELF']);
  ?&gt;
  </code></pre>
  
  <p>This is an example for a stand alone nav link:</p>
  
  <pre><code>&lt;li class="&lt;?php if ($current_page == "index.php"){ echo "active "; }?&gt; item"&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>This is an example for the drop down menu:</p>
  
  <pre><code>&lt;li class="&lt;?php if ($current_page == "index.php"){ echo "active "; }?&gt; item has-dropdown"&gt;&lt;a href="about.php"&gt;About Us&lt;/a&gt;...
  </code></pre>
  
  <hr>
  
  <p>Now the code for the sub nav's so far isn't working for me, but here it is with the real code!</p>
  
  <pre><code>&lt;?php 
      $cp = basename($_SERVER['PHP_SELF']);
      $cf = dirname($_SERVER['PHP_SELF']);
  ?&gt;
  </code></pre>
  
  <p>Here is an example for a stand alone nav link:</p>
  
  <pre><code>&lt;li class="&lt;?php if ($cp == "index.php"){ echo "active "; }?&gt; item"&gt;&lt;a href="/index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Here is an actual drop down menu from my nav.</p>
  
  <pre><code>&lt;li class="&lt;?php if ($cp == "courses.php" || $cp == "oshawa.php" &amp;&amp; $cf == "courses" || $cp == "bowmanville.php" &amp;&amp; $cf == "courses"){ echo "active "; }?&gt; item has-dropdown"&gt;
      &lt;a href="/courses.php"&gt;Courses&lt;/a&gt; &lt;!-- COURSES --&gt;
      &lt;ul class="dropdown"&gt;
          &lt;li&gt;&lt;a href="/courses.php"&gt;Courses&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Locations&lt;/label&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/courses/oshawa.php"&gt;Oshawa&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/courses/bowmanville.php"&gt;Bowmanville&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>This specifically is where the code breaks, the first part works fine, but the second we add the &amp;&amp; $cf == "courses" it breaks.</p>
  
  <pre><code>$cp == "oshawa.php" &amp;&amp; $cf == "courses" 
  </code></pre>
  
  <p>I don't think it's a formatting issue, I think it's just the code itself, not sure where to go from here. I'm not very good with PHP, all help is appreciated, thanks =)</p>