Jump to content

Navigation - Processwire is crazy


FvG
 Share

Recommended Posts

Why is it crazy? I just re-built the event and news systems which took me about 4 hours each in CodeIgniter in about 40 minutes using PW.

The system is great, though I have some problems with my nav.

I want it to show almost all pages of my site, excluding the children of news/ and events/.

This is how I started:

function nav(Pages $pages)
{
	$root = $pages->get('/');

	echo '<li><a href="'.$root->url.'">'.$root->title.'</a></li>';

	navElement($root);
}

function navElement(Page $site)
{
	$sites = $site->children;

	foreach ($sites as $site)
	{
		echo '<li><a href="'.$site->url.'">'.$site->title.'</a>';

		if ($site->numChildren)
		{
			echo '<ul>';

			navElement($site);

			echo '</ul>';
		}

		echo '</li>';
	}
}

// And then use
nav($pages);

How would you to that? I thought about something like

$hideChildren = array(1010, 1011);

// ...
if ($site->numChildren and ! in_array($site->id, $hideChildren))

An other way would be just to hide those pages but I want to keep them searchable and I think there's no way to auto-hide sites of a specific template, is there?

Thanks for Processwire and your help :D

  • Like 1
Link to comment
Share on other sites

Of course it's the same but easier to setup and much more flexible than yours ;)

You'd have to filter them out here:

$sites = $site->children;

With like

$sites = $site->children("template!=news|events");

And also make sure you got any children before looping:

if(count($sites)){ ...

Also want to mention $site->numChildren isn't access/published aware ... You'd better do count($page->children("template!=news|events"))

Link to comment
Share on other sites

Thanks for your help :)

What about my current one?

function nav(Pages $pages)
{
	$root = $pages->get('/');

	echo '<li><a href="'.$root->url.'">'.$root->title.'</a></li>';

	navElement($root);
}

function navElement(Page $site, $level = 1)
{
	$criteria = 'parent!=/news/|/termine/';

	$sites = $site->children($criteria);

	foreach ($sites as $site)
	{
		echo '<li><a href="'.$site->url.'">'.$site->title;

		if (count($site->children($criteria)))
		{
			if ($level !== 1)
			{
				echo ' »';
			}

			echo '</a><ul>';

			navElement($site, $level + 1);

			echo '</ul>';
		}
		else
		{
			echo '</a>';
		}

		echo '</li>';
	}
}

// use
nav($pages);
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...