Jump to content

randomising the page array order


benbyf
 Share

Recommended Posts

Hi, I'm trying to combine two find() arrays in a random order but currently can only make it give me back the same order each time. here's what im working with:

$works = $pages->find('template=work');
    $articles = $pages->find('template=article');
    $works->prepend($articles);
    $randWorks = $works->getRandom(count($works));

    foreach($randWorks as $child) {
      $class = $child === $page->rootParent ? " class='active'" : '';
      echo "<a$class href='{$child->url}'>{$child->title}</a>";
    }
Link to comment
Share on other sites

Sorry, forgot to mention that you also need to shuffle if you want random order rather than just random selection. So do this once you have $randWords populated:

$randWorks->shuffle();
  • Like 2
Link to comment
Share on other sites

  • 4 months later...

My comment is related to this topic.

I can not for the life of me figure out how to randomize something.

$onetestimonial = $pages->find("template=testimonial,limit=1");
foreach ($onetestimonial as $testes) {
	echo $testes->title;
}

I can get that far.

But I can not figure out how to randomize the output. There are currently 10 Testimonials. I'd like to display only one randomly.

I've seen $a->shuffle()
and getRandom()

but haven't the slightest idea how to use them.

Every attempt has resulted in some page error.

UGH, please help a PHPNEWB? lol

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

×
×
  • Create New...