Jump to content

Recommended Posts

Posted

Hi,

how do I get the six newest children of a page in my template?

I thought the right code would be:

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

But it always returns more than six pages...

Greets,

Nico

Posted

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');
Posted

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');

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...