function featured_content_sort_nodes in Featured Content 7.2
Same name and namespace in other branches
- 6.2 featured_content.module \featured_content_sort_nodes()
- 6 featured_content.module \featured_content_sort_nodes()
- 7 featured_content.module \featured_content_sort_nodes()
Sort nodes based on sort key.
1 call to featured_content_sort_nodes()
- featured_content_block_view in ./
featured_content.module - Implements hook_block_view().
File
- ./
featured_content.module, line 2035 - Featured Content module for created related & featured content blocks.
Code
function featured_content_sort_nodes($nodes, $sort_key, $numeric = TRUE, $order = 'desc') {
if (!empty($nodes)) {
foreach ($nodes as $node) {
$key = $node->{$sort_key} . '' . $node->nid;
$tmp[$key] = $node;
}
$tmp_keys = array_keys($tmp);
$sort_by = $numeric ? SORT_NUMERIC : SORT_REGULAR;
if ($order == 'desc') {
rsort($tmp_keys, $sort_by);
}
else {
sort($tmp_keys, $sort_by);
}
foreach ($tmp_keys as $tmp_key) {
$sorted_nodes[] = $tmp[$tmp_key];
}
return $sorted_nodes;
}
}