Jump to content

What is the last (or first) child in physical order?


opalepatrick
 Share

Recommended Posts

$pages->find('parent=/blog/')->last();

This finds the last child by id order, but how can I get the last or first child if I order them by moving them in the admin list of child pages? Basically I want to choose a post to promote maybe by moving the post to the top or bottom of the list of posts in admin.

Thanks

PS. I know I could choose the id, but I don't really want to have to change the template every time.

Link to comment
Share on other sites

If you want results in a specific order, use "sort":

$pages->find('parent=/blog/, sort=sort')->last();

// and if you want just one item, don't forget limit
// (or use get(), and check viewability separately)
$pages->find('parent=/blog/, sort=sort, limit=1')->last();
  • 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

×
×
  • Create New...