In inc/show.news.php find this:
- Code: Select all
foreach ($query as $bg => $row){
and add above:
- Code: Select all
if (isset($sortbyxfield)){
$path_to_xfields = '../data/xfields-data.txt';
foreach (file($path_to_xfields) as $name => $value) {
list($id, $xfieldsdata) = explode("|>|", trim($value), 2);
$xfieldsdata = explode("||", $xfieldsdata);
foreach ($xfieldsdata as $xfielddata) {
list($xfielddataname, $xfielddatavalue) = explode("|", $xfielddata);
$xfields_data[$id][$xfielddataname] = $xfielddatavalue;
}
}
if (!function_exists("sortbyxfield")) {
function sortbyxfield($a, $b) {
global $xfields_data, $sortbyxfield;
if ($xfields_data[$a['id']][$sortbyxfield[0]] == $xfields_data[$b['id']][$sortbyxfield[0]]){
return 0;
}
else{
if(strtolower($sortbyxfield[1]) == 'asc'){
return ($xfields_data[$a['id']][$sortbyxfield[0]] < $xfields_data[$b['id']][$sortbyxfield[0]]) ? -1 : 1;
}
else{
return ($xfields_data[$a['id']][$sortbyxfield[0]] < $xfields_data[$b['id']][$sortbyxfield[0]]) ? 1 : -1;
}
}
}
}
usort($query, 'sortbyxfield');
}
How to use it:
Add something like this to your include code:
- Code: Select all
$sortbyxfield = array('test', 'ASC');
"test" is the name of the XField and "ASC" is the order. You can show news in an ascending order ("ASC") or in a descending order ("DESC").
