Beate Posted November 1, 2016 Posted November 1, 2016 Hello, my menu is like this: /filme/ /filme/kultur/ /filme/natur/ /filme/menschen/ /filme/spielfilm/ And on the front page there should be 2 random films from each of this categories. How can I split the founded pages? $filme_kultur = $pages->find("template=film, sort=random, parent=/filme/kultur/, limit=2"); This dosn't work: $filme = $filme_kultur[0]->add($filme_natur[0])->add($filme_menschen[0])->add($filme_spielfilm[0])->add($filme_kultur[1])->add($filme_natur[1])->add($filme_menschen[1]); They should be in this order, and I could't call the find order twice because the random depents on the first call, so that I don't get the same film twice. Thanks!
AndZyk Posted November 1, 2016 Posted November 1, 2016 Hello Beate, maybe this will help you: $films = $pages->get("/filme/"); foreach ($films->children as $category) { foreach ($category->children("sort=random, limit=2") as $film) { echo $film->title; } } It is not necessary to add all pages to one array, you could just loop trough them, if I understood you correctly. Regards, Andreas 1
Beate Posted November 1, 2016 Author Posted November 1, 2016 Thanks! This is indeed cool But not like desired.. Your code gives /filme/kultur/a/ /filme/kultur/b/ /filme/menschen/c/ /filme/menschen/d/ /filme/natur/e/ /filme/natur/f/ /filme/spielfilm/g/ /filme/spielfilm/h/ But I'd like to have /filme/kultur/a/ /filme/menschen/c/ /filme/natur/e/ /filme/spielfilm/g/ /filme/kultur/b/ /filme/menschen/d/ /filme/natur/f/ /filme/spielfilm/h/ and if I repeat the code I might get the same film twice...
Robin S Posted November 2, 2016 Posted November 2, 2016 How about... foreach($pages->get("/filme/")->children() as $p) { $genres[$p->name] = $p->children("sort=random, limit=2"); } for($i = 0; $i <= 1; $i++) { foreach($genres as $genre) { if($genre->eq($i)) { echo $genre->eq($i)->title; } } } 1
Beate Posted November 2, 2016 Author Posted November 2, 2016 Thank you very much! Works like a charm and is much cleaner than my code
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