Jump to content

$pages->get("parent=/") not working


Manaus
 Share

Recommended Posts

I'm trying to make a navigation menu, for fetching all the subpages of the root I use this selector:

$menu_pages = $pages->get("parent=/");

But I when iterating on the array and printing the pages url I get a "Notice: Trying to get property 'url' of non-object" error.
The array is fetched through this code:

$menu_pages = $pages->get("/")->children

I'd like to know why the first selector is failing.

Thanks!

Link to comment
Share on other sites

1 hour ago, Manaus said:

I'd like to know why the first selector is failing.

 

1 hour ago, Manaus said:
$menu_pages = $pages->get("parent=/");

Here you are getting a single page ($pages->get). You are looping through it and the value in each loop is a value of a property in that page. These will mainly be strings (e.g. 'My page title') or integers, but there could be a Pageimages in there as well, if your page template has an images field. Either way, 'My page title'->url does not exist since this is a string (a non-object), hence the notice.

1 hour ago, Manaus said:
$menu_pages = $pages->get("/")->children

This selector returns a collection, a PageArray. When you loop through it, each value in the loop is a Page object. Hence, $pageInLoop->url works. Although it starts with a $pages->get, the chaining of ->children ends up with getting the children of "/", i.e. a PageArray.

  • Like 2
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...