Jump to content

Split found pages?


Beate
 Share

Recommended Posts

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!

 

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
        }
    }
}

 

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