ecshop调取文章可做成文章频道调取文章可按倒序正序同时可以设定
发布时间:08/01 来源:未知 浏览:
关键词:
本案例按index.php 讲解:
1. 在任何页面php页面比方(index.php goods.php)下面 ?>增添
/*------------------------------------------------------ */
//-- PRIVATE FUNCTIONS
/*------------------------------------------------------ */
function index_get_class_list_articles($cat_id='0',$list_type='0',$list_num='10',$list_order='add_time DESC'){
$cat_str = get_article_children($cat_id);
$sql = 'SELECT article_id, title, add_time, file_url, open_type ' .
' FROM ' . $GLOBALS['ecs']->table('article') . ' WHERE ' ;
if($cat_id!='0'){
$sql =$sql.$cat_str." and " ;
}
$sql =$sql.' article_type='.$list_type .' ORDER BY '.$list_order.' LIMIT ' . $list_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]['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']);
}
return $arr;
}
2. 在index.php $smarty->assign('hot_goods', get_recommend_goods('hot')); // 热点文章 下面增添 $smarty->assign('list_articles13', index_get_class_list_articles('13','0','9','add_time DESC'));
//13为文章分类ID,别告诉我你不知道如何看;0代表一般的文章;9是文章显示数目;add_time (DESC倒序,ASC正序)
3.index.dwt增添下面代码: 13代表文章分类ID <!--{foreach from=$list_articles13 item=article}-->
<li><a title="{$article.title|escape:html}" href="{$article.url}">{$article.title}</a></li>
<!--{/foreach}-->
4.$smarty->assign('list_articles13', index_get_class_list_articles('13','0','9','add_time DESC'));
//13为文章分类ID,别告诉我你不知道如何看;0代表一般的文章;9是文章显示数目;add_time (DESC倒序,ASC正序) 假如吧:DESC改成ASC $smarty->assign('list_articles13', index_get_class_list_articles('13','0','9','add_time ASC'));
那么前台排序就不一样了如图: 看前台: