Jump to content

How to hide Pages from the Topnavi via Adminmenu


Luis
 Share

Recommended Posts

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 :)

  • Thanks 1
Link to comment
Share on other sites

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");
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...