1 (edited by 2011-07-29 22:11:14)

Topic: [HACK] Sort News By (show_news.php)

Name: Sort News By (show_news.php)
Author: Flexer & NyNe
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: If you want to sort you news by a specific field like by author, title, ....
Instructions:

this hack will allow you to sort ascending and descending
Add this between

}else{ $count_all = count($all_news); }

and

$i = 0;

of ./inc/shows.inc.php:

// Sort News v1.1 - Start addblock
// To specify sorting, put the following in your include code:
// $sortby = X;
// Where X is a number from 0-6, which mean the following:
// 0 = sort by time
// 1 = sort by author
// 2 = sort by title
// 3 = sort by short story
// 4 = sort by long story
// 5 = sort by avatar
// 6 = sort by category
//
// To specify ascending/descending, put the following in your include code:
// $sortad = X;
// Where X is either "a" or "d"
//
// The lines below will automatically sort your news if news if the sort variables are unset
if (!isset($sortby)) { $sortby="0"; } if (!isset($sortad)) { $sortad="a"; }

// DO NOT EDIT BELOW
if (isset($sortby)) {
$every_news = $all_news;
if (!function_exists('sortcmp')) {
function sortcmp($a, $b) {
global $every_news, $sortby;

$news_a = explode('|', $every_news[$a]);
$news_b = explode('|', $every_news[$b]);

return strnatcasecmp($news_a[$sortby], $news_b[$sortby]);
}
}
uksort($all_news, 'sortcmp');
if ($sortad=="d") { $all_news = array_reverse($all_news); }
unset($sortby, $sortad);
}
// Sort News v1.1 - End addblock


use the following parameters with your CN include news
$sortad, $sortby as explained in the code.