Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Saad Imran's solution works alright except for if you would like multiple navigation items in the same list. I had to change a few lines to get it to generate validated list of items. I also added indents to make generated code more readable. I'm using spaces but this can be easily changed to tabs if you prefer, just replace 4 spaces with <code>"\t"</code>. (note you must use double quotes, not single quotes, otherwise php doesn't replace with a tab character but actually a \t)</p> <p>I am using this in codeigniter 2.1.0 with superfish (PHP5)</p> <pre><code>function GenerateNavHTML($nav, $tabs = "") { $tab=" "; $html = "\n$tabs&lt;ul class=\"sf-menu\"&gt;\n"; foreach($nav as $page) { //check if page is currently being viewed if($page['link'] == uri_string()) { $html .= "$tabs$tab&lt;li class=\"current\"&gt;"; } else { $html .= "$tabs$tab&lt;li&gt;"; } $html .= "&lt;a href=\"$page[link]\"&gt;$page[name]&lt;/a&gt;"; //Don't generate empty lists if(isset($page['sub'][0])) { $html .= $this-&gt;GenerateNavHTML($page['sub'], $tabs.$tab); } $html .= "&lt;/li&gt;\n"; } $html .= $tabs."&lt;/ul&gt;\n"; return $html; } </code></pre> <p>I was getting (switched to ol for clarification) </p> <pre><code>1. Home 1. About Us 1. Products 1. sub-product 1 1. sub-product 2 1. Contact </code></pre> <p>now i get</p> <pre><code>1. Home 2. About Us 3. Products 1. sub-product 1 2. sub-product 2 4. Contact </code></pre> <p>Nicely generated HTML</p> <pre><code>&lt;ul class="sf-menu"&gt; &lt;li class="current"&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="about.html"&gt;About Us&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="products.html"&gt;Products&lt;/a&gt; &lt;ul class="sf-menu"&gt; &lt;li&gt;&lt;a href="products-sub1.html"&gt;sub-product 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="products-sub2.html"&gt;sub-product 2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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