bhammeraz Posted January 27, 2011 Share Posted January 27, 2011 I'm trying to convert a site to this CMS system. The site uses a Sidebar Navigation menu that is the same on all pages. I have it running on the Parent page, but it won't show up on any children. Here is the code that is on my Parent page. <div id="sidebar"> <?php echo "<ul id='subnav' class='nav'>"; foreach($page->children as $child) echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; ?> </div> Thank you! Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 27, 2011 Share Posted January 27, 2011 Hi Bhammeraz, welcome to forums. As I understand it, you want to show the very same navigation [with children of root] on every page. therefore you can't use $page->children(), because in your templates, $page refers to page that's currently opened [therefore children() refers to different pages everytime] you want rather use something like this: <div id="sidebar"> <?php echo "<ul id='subnav' class='nav'>"; foreach($pages->get('/')->children as $child) echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; ?> </div> This first selects root page as reference and then iterates through it's children [i.e. first level pages on your site] Adam Link to comment Share on other sites More sharing options...
martinluff Posted January 27, 2011 Share Posted January 27, 2011 Couldn't you also use the code in the basic PW installation site where the sub nav gets generated by: <?php // Output subnavigation // // Below we check to see that we're not on the homepage, and that // there are at least one or more pages in this section. // // Note $page->rootParent is always the top level section the page is in, // or to word differently: the first parent page that isn't the homepage. if($page->path != '/' && $page->rootParent->numChildren > 0) { // We have determined that we're not on the homepage // and that this section has child pages, so make navigation: echo "<ul id='subnav' class='nav'>"; foreach($page->rootParent->children as $child) { $class = $page === $child ? " class='on'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } echo "</ul>"; } ?> So in this case it's checking if the section has sub-children rather than the page itself (plus there's an extra check in there for homepage that you don't really need I think. Anyway, hope that makes sense... 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 27, 2011 Share Posted January 27, 2011 @martinluff: To me it seems he needs sitewide navigation than subnavigation. And the homepage check is there, so if you are on homepage, subnavigation doesn't get rendered [so you don't and up having navigation AND subnavigation the same] Link to comment Share on other sites More sharing options...
martinluff Posted January 27, 2011 Share Posted January 27, 2011 Adam; just re-read the question - yes I think you're right, sorry for adding any confusion there. Link to comment Share on other sites More sharing options...
bhammeraz Posted January 27, 2011 Author Share Posted January 27, 2011 Adam, I just tested it and it works. Thank you ;D! -Ben 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