adrianmak Posted January 6, 2016 Share Posted January 6, 2016 Here is the code , which is copied and simplified from a function of pw's default profile function renderList($items) { if($items instanceof Page) $items = array($items); $out = ''; foreach($items as $item) { $out .= "<li><a href='$item->url'>$item->title</a></li>"; if ($item->hasChildren()) { $out .= renderList($item->children); } } $out = "<ul>$out</ul>\n"; return $out; } However the output markup is not I desired. <ul> <li><a href="/about/">About Us</a></li> <ul> <li><a href="/about/history/">History</a></li> <li><a href="/about/location/">Location</a></li> </ul> </ul> I want the markup should be, the parent root should be on the same level as of it's child. Like <ul> <li><a href="/about/">About Us</a></li> <li><a href="/about/history/">History</a></li> <li><a href="/about/location/">Location</a></li> </ul> Link to comment Share on other sites More sharing options...
kixe Posted January 6, 2016 Share Posted January 6, 2016 Quick shot. not tested function renderList($items, $wrap = true) { if($items instanceof Page) $items = array($items); $out = ''; foreach($items as $item) { $out .= "<li><a href='$item->url'>$item->title</a></li>"; if ($item->hasChildren()) { $out .= renderList($item->children, false); } } if ($wrap) $out = "<ul>$out</ul>\n"; return $out; } 1 Link to comment Share on other sites More sharing options...
adrianmak Posted January 6, 2016 Author Share Posted January 6, 2016 Quick shot. not tested function renderList($items, $wrap = true) { if($items instanceof Page) $items = array($items); $out = ''; foreach($items as $item) { $out .= "<li><a href='$item->url'>$item->title</a></li>"; if ($item->hasChildren()) { $out .= renderList($item->children, false); } } if ($wrap) $out = "<ul>$out</ul>\n"; return $out; } yeah~~~~~ it works. I was thinking, there should have some kind of indicator to not wrap the outter UL tag when transvering a list I scratched my head for few hrs but not clue. 1 Link to comment Share on other sites More sharing options...
bernhard Posted January 6, 2016 Share Posted January 6, 2016 one line when using http://modules.processwire.com/modules/markup-simple-navigation/ 'show_root' => true just in case you don't know somas great module 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now