FvG Posted March 7, 2013 Posted March 7, 2013 Why is it crazy? I just re-built the event and news systems which took me about 4 hours each in CodeIgniter in about 40 minutes using PW. The system is great, though I have some problems with my nav. I want it to show almost all pages of my site, excluding the children of news/ and events/. This is how I started: function nav(Pages $pages) { $root = $pages->get('/'); echo '<li><a href="'.$root->url.'">'.$root->title.'</a></li>'; navElement($root); } function navElement(Page $site) { $sites = $site->children; foreach ($sites as $site) { echo '<li><a href="'.$site->url.'">'.$site->title.'</a>'; if ($site->numChildren) { echo '<ul>'; navElement($site); echo '</ul>'; } echo '</li>'; } } // And then use nav($pages); How would you to that? I thought about something like $hideChildren = array(1010, 1011); // ... if ($site->numChildren and ! in_array($site->id, $hideChildren)) An other way would be just to hide those pages but I want to keep them searchable and I think there's no way to auto-hide sites of a specific template, is there? Thanks for Processwire and your help 1
Soma Posted March 7, 2013 Posted March 7, 2013 How about http://modules.processwire.com/modules/markup-simple-navigation/ You can also specify a selector in the option array like "template!=news|event" for example.
FvG Posted March 7, 2013 Author Posted March 7, 2013 Looks good but it seems to be pretty much the same I got and doesn't solve my problems. That filter looks good, gonna try that.
Soma Posted March 7, 2013 Posted March 7, 2013 Of course it's the same but easier to setup and much more flexible than yours You'd have to filter them out here: $sites = $site->children; With like $sites = $site->children("template!=news|events"); And also make sure you got any children before looping: if(count($sites)){ ... Also want to mention $site->numChildren isn't access/published aware ... You'd better do count($page->children("template!=news|events"))
Soma Posted March 7, 2013 Posted March 7, 2013 Addition.. you could also use selector parent!=id|/path/ to exlude all children.
FvG Posted March 7, 2013 Author Posted March 7, 2013 Thanks for your help What about my current one? function nav(Pages $pages) { $root = $pages->get('/'); echo '<li><a href="'.$root->url.'">'.$root->title.'</a></li>'; navElement($root); } function navElement(Page $site, $level = 1) { $criteria = 'parent!=/news/|/termine/'; $sites = $site->children($criteria); foreach ($sites as $site) { echo '<li><a href="'.$site->url.'">'.$site->title; if (count($site->children($criteria))) { if ($level !== 1) { echo ' »'; } echo '</a><ul>'; navElement($site, $level + 1); echo '</ul>'; } else { echo '</a>'; } echo '</li>'; } } // use nav($pages);
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