Jump to content

Page not appearing when using ->children


gnome
 Share

Recommended Posts

Hi all

I've been using ProcessWire for a while and am completely comfortable using it. BUT, for some reason, today I am unable to echo out a page link!

I have a section (About Us), which did have 4 children. Today I have added a 5th child page, but it refuses to be added to the navigation. I've echoed out the count of children and it is coming back as 4, even though there are now 5. The page is published and saves fine. I've deleted it and re-added it, to no avail.

Has anyone else ever had this issue? Any suggestions more than welcome!

Code for generating menu is below.

$navigation = $page->rootParent->navigation;

if(count($navigation) > 0)
{
	//echo count($navigation);
	foreach($navigation as $p)
	{						
		$children = $p->children;
		//echo $p->url;
		//echo count($children);
		
		// count children (exclude certain templates)
		if(count($children) && $p->is("template!=news-page|team-page|development-land-page|sheep-sales-page|produce-sales-page|grass-keep-page|property-list-page|property-auctions-page"))
		{
			// accordion header
			?>
			<a href="#" class="submenu<?php if($page->parents->has($p) || $p === $page) echo '-current'; ?>"><?= $p->title; ?></a>
			<?php
			// expandable sub-menu
			?>
			<div class="sub-sub-links <?php if($page->parents->has($p) || $p === $page) echo 'active'; ?>">
				<?php
				foreach($children as $child)
				{
					?>
					<a href="<?= $child->url; ?>" <?php if($child === $page) echo 'class="sub-sub-links-current"'; ?>><?= $child->title; ?></a>
					<?php
				}
				?>
			</div>
			<?php
		}
		else
		{
			// single page
			if ($page->parents->has($p) || $p === $page)
			{
				$class = 'sub-links-current';
			}
			else
			{
				$class = '';
			}
			?>
			<a href="<?= $p->url; ?>" class="<?= $class; ?>"><?= $p->title; ?></a>
			<?php
		}
	}

Link to comment
Share on other sites

What does that output for you when directly grabed?

echo $pages->get("/about/")->children;

echo $pages->get("/about/")->children->count;

what is this rooparent "navigation" you get the 

Link to comment
Share on other sites

Thank-you Soma! For mentioning the "navigation" field. It turns out that this is used to generate the menu, rather than just getting the page children. So you have to manually add the new page(s) to the navigation field for it to appear in the menu. Thank-you to all for your help  and suggestions.

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...