Jump to content

Recommended Posts

Posted
$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.

Posted

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
Posted

get(selector) does a findOne(selector);

findOne(selector) does a find(selector)->first();

$pages->get('parent=/blog/, sort=sort')
  • Like 3

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
×
×
  • Create New...