Note that there are some explanatory texts on larger screens.

plurals
  1. POActive Class in Navbar - Whats wrong with my php?
    primarykey
    data
    text
    <p>I'm having a bit of trouble trying to get my head around some php code. To explain:</p> <p>I have a navbar made from bootstrap. I want this nav bar to change it's active class depending on the page. I have a subnav within the navbar with an li class of 'dropdown'. When this page is active this li class wants to change to 'dropdown active' When other pages are active, they just want a simple class of 'active'.</p> <p>My code is as follows: PHP:</p> <pre><code> $pageLoc = 'where'; $nav_items = array('index'=&gt;'Home', 'where'=&gt;'Where?', 'appeals'=&gt;'Current Appeals', 'news'=&gt;'Latest News', 'events'=&gt;'Events', 'dontate'=&gt;'Dontate', ); $nav_sub = array('africa'=&gt;'Africa', 'bangladesh'=&gt;'Bangladesh', 'gaza'=&gt;'Palestine/Gaza', 'kashmir'=&gt;'Kashmir', 'pakistan'=&gt;'Pakistan', 'uk'=&gt;'United Kingdom' ); foreach ($nav_items as $nav_href=&gt;$nav_title) { if ($pageLoc == $nav_href) &amp;&amp; ($pageLoc == 'where') { echo '&lt;li class="dropdown active"&gt;' . $nav_title . '&lt;/li&gt;'; } elseif ($pageHref == $nav_href) &amp;&amp; ($pageLoc == 'no') { echo '&lt;li class="dropdown"&gt;' . $nav_title . '&lt;/li&gt;'; } elseif ($pageHref == $nav_href) { echo '&lt;li class="active"&gt;' . $nav_title . '&lt;/li&gt;'; } else { echo '&lt;li&gt;' . $nav_title . '&lt;/li&gt;'; } } </code></pre> <p>Navbar:</p> <pre><code>&lt;ul class="nav pull-right"&gt; &lt;li class="pull-right"&gt; &lt;a class="btn-danger" href="donate"&gt;&lt;i class="icon-medkit"&gt; DONATE!&lt;/i&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ul class="nav pull-right"&gt; &lt;li class=""&gt; &lt;a href="../"&gt;Home&lt;/a&gt; &lt;/li&gt; &lt;li class="dropdown"&gt; &lt;a href="../where/" class="dropdown-toggle disabled" data-toggle="dropdown"&gt; Where? &lt;b class="caret"&gt;&lt;/b&gt; &lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li class="nav-header"&gt;Where we operate&lt;/li&gt; &lt;li class="divider"&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../where/africa"&gt;Africa&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../where/bangladesh"&gt;Bangladesh&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../where/palestine-gaza"&gt;Palestine/Gaza&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../where/kashmir"&gt;Kashmir&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../where/pakistan"&gt;Pakistan&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class=""&gt; &lt;a href="../appeals"&gt;Current Appeals&lt;/a&gt; &lt;/li&gt; &lt;li class=""&gt; &lt;a href="../news"&gt;Latest News&lt;/a&gt; &lt;/li&gt; &lt;li class=""&gt; &lt;a href="../events"&gt;Events&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I am aware that this php is generating a syntax error. I am no pro unfortunately! :( This is </p> <pre><code>what I originally had: foreach ($nav_items as $nav_href=&gt;$nav_title) { if ($pageHref == $nav_href) { echo '&lt;li class="active"&gt;' . $nav_title . '&lt;/li&gt;'; } else { echo '&lt;li&gt;' . $nav_title . '&lt;/li&gt;'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload