Nico Knoll Posted November 1, 2011 Share Posted November 1, 2011 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 Link to comment Share on other sites More sharing options...
Soma Posted November 1, 2011 Share Posted November 1, 2011 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 More sharing options...
ryan Posted November 1, 2011 Share Posted November 1, 2011 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 More sharing options...
Nico Knoll Posted November 1, 2011 Author Share Posted November 1, 2011 Thanks, the first one worked for me Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now