Jump to content

Get the six newest childen from a page


Nico Knoll
 Share

Recommended Posts

I'm not sure about your code, it wouldn't work for me...

Right approach would be

$news = $pages->get('/news/')->find('sort=-created, limit=6');

or

$news = $pages->get('/news/')->children('sort=-created, limit=6');
Link to comment
Share on other sites

Consistent with jQuery syntax, $pages->get() returns one item, whereas $pages->find() returns multiple. So your original code would only ever return 1 page.

Soma is right on this, though just want to mention that you probably want the second one (using children), because like with jQuery, calling find() on a page will return not just children but anything in that branch of the tree. Whereas children() will just return direct children of that page.

Also, you can use your original syntax too if you prefer, but substitute $pages->get() with $pages->find(), so that you are aren't asking for just one item, i.e.

$news = $pages->find('parent=/news/, sort=date, limit=6');
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...