Luis Posted October 25, 2012 Share Posted October 25, 2012 Hi there, I´m using the basic navigation output from Ryan´s example site. I got Pages assigned to the Basic-Page Template which I don´t want to be shown in the Navigation. So here is my solution: Create a new field called: navhide Type: Checkbox Label: Do you want to hide this page from Topnavigation? Edit the Basic-Page Template and add the created field. Open your head.inc and add the following to where your Topnavigation shoud be outputted: <ul class="nav"> <?php $homepage = $pages->get("/"); $children = $homepage->children("navhide=0"); $children->prepend($homepage); foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; echo "<li$class><a href='{$child->url}'>{$child->title}</a></li>"; } ?> </ul> Please remember that the given html classes are from one of my projects, so feel free to add your own. You now find a new field in Pages assigned to basic-page template called navhide. If checked your Pages will be hidden in navigation. Hope this will work for someone 1 Link to comment Share on other sites More sharing options...
Wanze Posted October 25, 2012 Share Posted October 25, 2012 Hi Luis, You could also set Status of a Page to hidden, then ProcessWire does not include the Page in searches and lists (Menu). This setting can be found under the "Settings" tab of the page -> Hidden: Excluded from lists and searches. If you want a hidden page to appear in a search, add "include=hidden" in the Selector, for example: $pages->find("template=basic-page, include=hidden"); //or $homepage->children("include=hidden"); 1 Link to comment Share on other sites More sharing options...
Luis Posted October 25, 2012 Author Share Posted October 25, 2012 Hi Wanze, ah didn´t thought about the include selector. Yes, the main reason I added the hide field was for the search results. The include selector would be the smarter way. Link to comment Share on other sites More sharing options...
Gabi Posted March 26, 2013 Share Posted March 26, 2013 Hi there, If I understood well, if one wants to exclude certain pages from navigation, but to include them in searches, the two options are: create a checkbox to include/exclude pages from navigation; could by created to be turned on/off by default so one only has to check it for pages not desired in navigation change the page status to hidden and include them specifically in searches; but, in this case, what happens to the pages that have to be excluded from both the navigation and searches? Link to comment Share on other sites More sharing options...
ryan Posted March 27, 2013 Share Posted March 27, 2013 reate a checkbox to include/exclude pages from navigation; could by created to be turned on/off by default so one only has to check it for pages not desired in navigation This would be a fine way to go. Since you can't have a checkbox "checked" by default, you would want to use and name/label your field accordingly and use your checkbox to toggle the non-default behavior when checked. change the page status to hidden and include them specifically in searches; but, in this case, what happens to the pages that have to be excluded from both the navigation and searches? ProcessWire doesn't know the difference between navigation and searches. Every API call to ProcessWire is a search, whether you are using it for navigation or not (ProcessWire doesn't know what you are using it for). If "hidden" is checked, then it excludes it from the search, unless you add "include=hidden" or "include=all" to the selector. So if you want a page to be excluded from both navigation and searches, then you would want to make it hidden and avoid having a "include=..." in your selector. There are also other built-in ways to exclude a page from appearing in results from API calls, including the "unpublished" status, and access control. Link to comment Share on other sites More sharing options...
Gabi Posted March 31, 2013 Share Posted March 31, 2013 Thank you. I get it now. 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