Christoph Posted December 3, 2011 Share Posted December 3, 2011 Would like to have a checkbox on the Setting tab, maybe in the "status" fieldset, where I can decide to publish a page but not to let it count for the main navigation or sub navigation. I often have pages that just need a link in the content area but no showing up in the any navigation sections. Link to comment Share on other sites More sharing options...
formmailer Posted December 3, 2011 Share Posted December 3, 2011 You can use the status "Hidden" for this. It's on the settings tab of the page. /Jasper 1 Link to comment Share on other sites More sharing options...
Christoph Posted December 5, 2011 Author Share Posted December 5, 2011 Thanks for your reply, Jasper. The problem with the hidden status is, that you can't find the page in search results. Having a page that you don't want to show up in navigation doesn't mean it also shouldn't be searchable. Maybe this should be separated. Link to comment Share on other sites More sharing options...
Pete Posted December 5, 2011 Share Posted December 5, 2011 You can change the search to include hidden pages: $matches = $pages->find("title|body|sidebar~=$q, limit=50, include=hidden "); 1 Link to comment Share on other sites More sharing options...
formmailer Posted December 5, 2011 Share Posted December 5, 2011 Pete's solution is probably the best. Another workaround would be to move the page out of the ordinary pagetree and place it under it's own parent (eg. dontshow). That would allow you to do the following: list all pages in the navigation except those with parent "dontshow". /Jasper Link to comment Share on other sites More sharing options...
apeisa Posted December 5, 2011 Share Posted December 5, 2011 I think best solution here would be checkbox field "don't show in navigation" and then just exclude those pages in your navigation selectors. It would be great to have it next to hidden, but that might require module to do so. Link to comment Share on other sites More sharing options...
Christoph Posted December 9, 2011 Author Share Posted December 9, 2011 Thanks for your help, guys! Will go with Pete's solution for now. Link to comment Share on other sites More sharing options...
digitex Posted January 19, 2012 Share Posted January 19, 2012 I have a similar problem in that I have a navigation menu featuring a javascript dropdown. Some of the top level pages in the navigation I want to have their children display in the drop down while some I don't. There's a news and events page for example that if all it's children were displayed in the drop down would make for a loooonng menu. I used Pete's solution by making the pages hidden and including hidden pages in the list on the news and events page BUT... The whole point of a CMS is to allow people who have no real expertise to edit and add new content and to expect them to remember to mark each new page they create as hidden is asking a lot and I anticipate a big mess that I'll have to clean up. A solution would be to have a way to mark a template as hidden so that all pages created using that template will by default be hidden but that's not possible either. Having a checkmark field to determine if a page is to be included in drop down navigation is probably a good solution but also requires the user to remember to mark it. Is there an easier way? Can I add in something to the effect of: if the page is a child of news and events then exclude it? I don't know how you would code that. Link to comment Share on other sites More sharing options...
formmailer Posted January 19, 2012 Share Posted January 19, 2012 You could do something like foreach($children as $child) { if($child->numChildren && $child->parent!="/news/") { // Your code to subpages list your pages here } } Note: didn't test the code, just written in the browser Hope this helps! //Jasper Link to comment Share on other sites More sharing options...
digitex Posted January 19, 2012 Share Posted January 19, 2012 Thanks Jasper. That's the kind of thing I'd like to do but for some reason I can't make it work. I'm using Ryan's excellent listChildrenTree function: function listChildrenTree($children) { echo "<ul>\n"; foreach($children as $child) { echo "<li><a href='{$child->url}'>{$child->title}</a> "; if($child->numChildren) listChildrenTree($child->children); echo "</li>\n"; } echo "</ul>"; } listChildrenTree($pages->get('/')->children); And when I add in your addition it doesn't do anything. If I keep working with processwire i hope I'll eventually be able to figure this stuff out myself but I'm not there yet. Link to comment Share on other sites More sharing options...
ryan Posted January 19, 2012 Share Posted January 19, 2012 You can easily exclude pages by any factor that you want to by using a selector when the pages are loaded, or an if() statement after. Jasper was on the right track, but the example he posted wouldn't work just because $child->parent is an object and not a string. However, you could do something like this instead: foreach($children as $child) if($child->template == 'some-template') continue; // skip it // ... otherwise display it ... } Another example: // display children, except for those with parent 'products' or those using template 'employee' if($child->numChildren && $child->name != 'products' && $child->template != 'employee') { listChildrenTree($child->children); } You can also do something like this: // list children that aren't using template employee listChildrenTree($child->children("template!=employee"); Link to comment Share on other sites More sharing options...
formmailer Posted January 20, 2012 Share Posted January 20, 2012 (edited) You can easily exclude pages by any factor that you want to by using a selector when the pages are loaded, or an if() statement after. Jasper was on the right track, but the example he posted wouldn't work just because $child->parent is an object and not a string. Sorry about that, I checked and used the same code on my site, but with one small difference: I used a pageID as the selector and that works of course, since that's a string value /Jasper PS: Ryan's last example missed a bracket. Not a big thing, but for the sake of completeness 8) : // list children that aren't using template employee listChildrenTree($child->children("template!=employee")); Edited January 20, 2012 by formmailer Link to comment Share on other sites More sharing options...
apeisa Posted January 20, 2012 Share Posted January 20, 2012 My solution is this. I keep list of all templates I want to shown on navigation on my site/config.php file: $config->navTemplates = 'home|basic-page|news|events'; I have templates like news-item, events-item etc who didn't make to the list. And whenever I loop normal navs I check against that list: $templates = $config->navTemplates; foreach($children("limit=50,template=$templates") as $child) { ...output here } 3 Link to comment Share on other sites More sharing options...
digitex Posted January 20, 2012 Share Posted January 20, 2012 (edited) God you guys are awesome. Thanks. The generosity of everyone who offers insight and helpful tips on this forum is humbling. You guys make me look good to my clients. They think I know what I'm doing. I have a template news-list that displays the headlines and dates of each article with a link to go to the page (it's the page that shows up when you click the News and events button in the navigation and a template called news-item which is the template every article uses. So Ryan's approach would work perfectly as I can simply exclude every page using the news-item template. Works! Just tried it. On to the next thing. Edited January 20, 2012 by digitex 1 Link to comment Share on other sites More sharing options...
RyanJ Posted March 28, 2013 Share Posted March 28, 2013 I thought I would just add my snippet of code that excludes a specific top page from my navigation menu. I used Ryan's example and added the notated line to it. I'm not sure if it is the best way to do it, but it works. <?php $root = $pages->get("/"); $children = $root->children(); $children->prepend($root); foreach($children as $child) { // Added to remove the site-map from my top menu. Replace site-map with the url if($child->name != 'site-map') { echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; }} ?> Link to comment Share on other sites More sharing options...
OLSA Posted September 25, 2014 Share Posted September 25, 2014 Hello, I created check field "skiper" and put it to template. In parent page set it ("check") and later inside navigation loop check if 1 - skip children (hide all of them from menu/submenu). // rendering submenu items if ( $item->hasChildren() && $item <> $homepage && !$item->skiper ) { echo treeMenu (....); } In that way user only need to do one setup, only inside parent page. Regards. p.s. sorry if this is not a way to go - today make first steps with PW Link to comment Share on other sites More sharing options...
bernhard Posted September 25, 2014 Share Posted September 25, 2014 Another workaround would be to move the page out of the ordinary pagetree and place it under it's own parent (eg. dontshow). That would allow you to do the following: list all pages in the navigation except those with parent "dontshow". then you would have URLs like domain.com/dontshow/sample that's why i don't like this approach. thank's for bringing up this post, just tried to exclude pages from nav using MarkusSimpleNavigation... something like 'selector' => 'template!=team' ...works like a charm you could also add a checkbox "hidenav" to your templates you want to be able to hide from navigation and then use a selector like this 'selector' => 'hidenav=0' its as simple as that - i'm amazed once more the complete code for my navigation, just for the record... <nav class="nav-main mega-menu"> <?php $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module $options = array( 'show_root' => true, 'outer_tpl' => '<ul class="nav nav-pills nav-main" id="mainMenu">||</ul>', 'selector' => 'hidenav=0' ); echo $treeMenu->render($options); ?> </nav> Link to comment Share on other sites More sharing options...
OLSA Posted September 25, 2014 Share Posted September 25, 2014 then you would have URLs like domain.com/dontshow/sample that's why i don't like this approach. No need for that - in my case parent page is "News", and children are news articles. In menu I have "News" button but don't want to show news articles in submenu. Just add to parent ("News") check field and it's simple to skip childrens from submenu inside navigation loop. thank's for bringing up this post, just tried to exclude pages from nav using MarkusSimpleNavigation... something like 'selector' => 'template!=team' Option with eg. "skiper" check field is that you can use it also on others templates and don't need to edit php. you could also add a checkbox "hidenav" to your templates you want to be able to hide from navigation and then use a selector like this 'selector' => 'hidenav=0' Yes that is my option - but I use it different . Sorry for missunderstanding - I wasn't so clear in my previous post. In my case (hide children from submenu and also use parent for "listing" view) working solution is this: add simple check field in parent page and iniside navigation loop (where is children rendering part) ask "if that parent has check field checked" skip children and go to next. Also same method is for any other page what you want to hide from navigation - only different is place and/or "question" inside navigation loop. regards 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