Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML Menu, php, highlight first item of its submenu item
    text
    copied!<p>I'm searching for a solution for automatic highlightning top menu items.</p> <p>Current situation looks like this: I have default menu stored in a .txt file:</p> <pre><code>&lt;li&gt;&lt;a href="index.php"&gt;HOME&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;MENU_1&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="submenu_1.php"&gt;Submenu_1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="submenu_2.php"&gt;Submenu_2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;MENU_2&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Submenu_1&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="sub_submenu_1.php"&gt;Sub_Submenu_1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="sub_submenu_2.php"&gt;Sub_Submenu_2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Submenu_2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="menu_3.php"&gt;MENU_3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="menu_4.php"&gt;MENU_4&lt;/a&gt;&lt;/li&gt; </code></pre> <p>So, when the <code>submenu</code>, or <code>sub_submenu</code>, or whatever item is a current page, I need its very top <code>MENU_X</code> parent item to be highlighted (as only the <code>MENU_X</code> items are visible on my page top bar).</p> <p>I made CSS style aplied to <code>MENU_X</code>, so when I set the top menu like:</p> <pre><code>&lt;li class="current"&gt;&lt;a href="#"&gt;MENU_1&lt;/a&gt; </code></pre> <p>it's highlighted by the <code>.current</code> CSS style.</p> <p>Now I'm searching for a PHP script which would do something like this (example only):</p> <pre><code>&lt;?php $currentPage = $_SERVER["PHP_SELF"]; $url_parts = Explode('/', $currentPage); $current_php_file = $url_parts[count($url_parts) - 1]; $raw_menu = file_get_contents("menu.txt"); $current_menu_item = '&lt;li&gt;&lt;a href="' . $current_php_file . '"&gt;' $top_menuitem_of_current_page = someFunctionToFindOut(); //need some script to find out $highlighted_menu_item = '&lt;li class="current"&gt;&lt;a href="' . $top_menuitem_of_current_page . '"&gt;'; $ready_menu = str_replace($top_menuitem_of_current_page, $highlighted_menu_item, $raw_menu); echo $ready_menu; ?&gt; </code></pre> <p>The code above basically would do the trick, but I need to call some function <code>someFunctionToFindOut()</code> to find out what is the <code>$top_menuitem_of_current_page</code>.</p> <p>Any suggestions?</p>
 

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