ecshop 文章排序 按照文章ID排序

2016-07-07 15:00 来源:www.chinab4c.com 作者:ecshop专家

在论坛看到很多朋友都在问这个问题。今天把这个代码贴出来。希望对大家有好处!

问过这个问题的都应该知道这一串代码

function index_get_class_articles($cat_aid, $cat_num)
{
$sql = "Select article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " Where cat_id = ".$cat_aid." and is_open = 1 LIMIT " . $cat_num;
$res = $GLOBALS['db']->getAll($sql);
$arr = array();
foreach ($res AS $idx => $row)
{
$arr[$idx]['id'] = $row['article_id'];
$arr[$idx]['title'] = $row['title'];
$arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
$arr[$idx]['cat_name'] = $row['cat_name'];
$arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
$arr[$idx]['url']= $row['open_type'] != 1 ?
build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
$arr[$idx]['cat_url']= build_uri('article_cat', array('acid' => $row['cat_id']));
}
return $arr;
}

大家只要修改成如下就OK了

function index_get_class_articles($cat_aid, $cat_num)
{
$sql = "Select article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " Where cat_id = ".$cat_aid." and is_open = 1 order by article_id desc LIMIT 0," . $cat_num;//这两个地方一定要注意,其他的都没有变化了。
$res = $GLOBALS['db']->getAll($sql);
$arr = array();
foreach ($res AS $idx => $row)
{
$arr[$idx]['id'] = $row['article_id'];
$arr[$idx]['title'] = $row['title'];
$arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
$arr[$idx]['cat_name'] = $row['cat_name'];
$arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
$arr[$idx]['url']= $row['open_type'] != 1 ?
build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
$arr[$idx]['cat_url']= build_uri('article_cat', array('acid' => $row['cat_id']));
}
return $arr;
}

具体效果请见:http://www.buy1388.com

回答:
不错哦。