Jump to content

Why is "Hidden: Excluded from lists and searches" abused for the menu creation?


Kai
 Share

Recommended Posts

I tried the demo template and discovered that also other menu builders are using the Status field of a page called "Hidden: Excluded from lists and searches" for the decision if a page should be part of the menu or not. 

$children = $homepage->children();   // does obviously read all non-hidden pages
foreach($children as $child) {...}

The admin should be able to decide: [ x ] show in menu   [ x ] hidden from searches 

Combining those options into one field is by design wrong.

Or have I missed any other option here? 

 

Link to comment
Share on other sites

Yes, exactly what I did. For others that have the same issue: 

1. Add Field: showinmenu (type: checkbox) 

2. Assign field to the template(s) you need

3. Put this into your _head.php: 

<ul class='topnav'>
	<?php 
	$children = $pages->get('/')->children()->find('showinmenu=1');
	
	// render an <li> for each top navigation item
	foreach($children as $child) 
	{
		if($child->id == $page->rootParent->id) 
		{
			// this $child page is currently being viewed (or one of it's children/descendents)
			// so we highlight it as the current page in the navigation
			echo '
			<li>
				<a class="nav-item is-active" href="'.$child->url.'">'.$child->title.'</a>
			</li>
			';
		}
		else 
		{
			echo '
			<li>
				<a class="nav-item" href="'.$child->url.'">'.$child->title.'</a>
			</li>
			';
		}
	}

	// output an "Edit" link if this page happens to be editable by the current user
	if($page->editable()) 
	{
		echo '
		<li>
			<a class="nav-item edit" href="'.$page->editUrl.'">Edit</a>
		</li>
		';
	}

?></ul>

 

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

×
×
  • Create New...