Skip to content

Instantly share code, notes, and snippets.

@rdeutz
Last active February 23, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdeutz/9058277 to your computer and use it in GitHub Desktop.
Save rdeutz/9058277 to your computer and use it in GitHub Desktop.
Show a number of modules form a larger number of modules randomly
<?php
$modlist=array('modpos01','modpos02','modpos03','modpos04','modpos05');
$allMods=count($modlist);
$show=array();
$elephantInCairo=0;
while(count($show) < 4 && $elephantInCairo < 100)
{
$c = rand (0 , $allMods-1);
if (!in_array($modlist[$c], $show))
{
if ($this->countModules($modlist[$c]))
{
$show[] = $modlist[$c];
}
}
$elephantInCairo++;
}
?>
<?php if (count($show)): ?>
<section id="mymodulerow">
<div class="container">
<h3>My Module Row</h3>
<div class="row">
<?php foreach($show as $m) : ?>
<div class="col-md-3">
<jdoc:include type="modules" name="<?php echo $m; ?>" style="xhtml" />
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif; ?>
Copy link

ghost commented Feb 17, 2014

Why not simply do:

<?php
$modlist=array('modpos01','modpos02','modpos03','modpos04','modpos05');
$show = array_rand($modlist, 4);
?>

@rdeutz
Copy link
Author

rdeutz commented Feb 23, 2016

because I can :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment