ECSHOP调用指定分类的文章列表
指定文章分类、数量,并按照日期排序
/** * 获得指定分类的文章列表,按照日期排序。 * * @access private * @param integer $article_cat_id * @param integer $num * @return array */ function get_articles_cat_id($article_cat_id,$num) { $sql = 'SELECT a.article_id, a.title, a.add_time, a.file_url, a.open_type' . ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a ' . ' WHERE a.is_open = 1 AND a.cat_id = '.$article_cat_id. ' ORDER BY a.add_time DESC LIMIT ' . $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'] = sub_str($row['title'],18); $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']), $row['cat_name']); } return $arr; }
category.php页面调用函数:
$smarty->assign('article', get_articles_cat_id(18,5));
category.dwt模版页
<!--{foreach from=$article item=cuxiao}--> <li><a href="{$cuxiao.url}" title="{$cuxiao.title}">{$cuxiao.short_title}</a></li> <!--{/foreach}-->