Added a new random sort order option

This commit is contained in:
Andy Miller
2014-08-25 08:56:38 -06:00
parent 4a1989e3a8
commit 65720df28d

View File

@@ -539,8 +539,14 @@ class Pages
}
}
// Sort by the new list.
asort($list);
// handle special case when order_by is random
if ($order_by == 'random') {
$list = $this->array_shuffle($list);
} else {
// else just sort the list according to specified key
asort($list);
}
// Move manually ordered items into the beginning of the list. Order of the unlisted items does not change.
if (is_array($manual) && !empty($manual)) {
@@ -568,4 +574,17 @@ class Pages
$this->sort[$path][$order_by][$key] = $info;
}
}
// Shuffles and associative array
protected function array_shuffle($list) {
$keys = array_keys($list);
shuffle($keys);
$new = array();
foreach($keys as $key) {
$new[$key] = $list[$key];
}
return $new;
}
}