Jump to content

Recommended Posts

Posted

Dumb question coming up. I can't get sorting to work. I show child pages (posts) of a parent page (news) on the homepage with this in the template:

$news = $pages->find("template=post");

foreach($news as $post) { ...

Sort order setting in the template or page is apparently ignored. The sort order is correct in the admin area, but shows up wrong on the home page.

What am I missing?

Posted

I think this may be your problem: https://processwire.com/api/selectors/
 

Quote

How to force pages to sort by their admin order with $pages->find()
Unlike $page->children(), the $pages->find() function does not automatically sort by the order they appear in the site tree. This is because $pages->find() is not limited to finding pages specific to one parent, so it may be pulling pages from multiple places (according to your selector). If your parent page(s) are not already sorting by a specific field, you may still tell the $pages->find() to sort by the parent's order by specifying "sort=sort" in your selector. This is the same as saying "sort by whatever order I dragged the pages to in the admin." But note that if the results have multiple parents, the resulting order isn't likely to be useful.

 

  • 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...