Jump to content

sort all grandchildren in order of all first, all second, all third... of categories


Purple
 Share

Recommended Posts

Hey all !

Can't seem to find any other topics answering my question.

My website as 5 categories, with up to 4 children each. My homepage has a grid where I want to return all images from children of all categories, but in the folowing order : all first children, then all second, then all third..

Now the only way I can structure this is :

foreach category{

child = category->children()

foreach child(limit=1 start=1){

echo children ->image;

}}

but I'd have to repeat that for any maximum number of children.

Any other ways ?

Edited by Purple
Link to comment
Share on other sites

  • Purple changed the title to sort all grandchildren in order of all first, all second, all third... of categories

@Purple your question is more related to php as to processwire. You better search in stackoverflow for these kind of question.

Anyway, you could use a for loop. This code gives you the first images of the first five category children. 

for ($i = 0; $i <= 4; $i++) {
    foreach($categories as $category) {
		$image = $category->children->eq($i)->images->first;
    }
}

 

  • Like 1
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

  • Recently Browsing   0 members

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