Jump to content
Luis

How to hide Pages from the Topnavi via Adminmenu

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...