欢迎来到元素模板www.ys720.com,本站提供专业的织梦模板网站模板ASPCMS模板网站修改/网站仿站
当前位置:主页 > 程序教程 > ECSHOP教程 >
ECSHOP教程

ecshop 首页调用 新闻文章

(元素模板) / 2020-06-22 17:10
在 index.php 结尾加上
function index_get_class_articles($cat_aid, $cat_num)
{
$sql = "SELECT article_id, title,open_type,cat_id,file_url,description,add_time 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]['description'] = $row['description'];
$arr[$idx]['file_url'] = $row['file_url']=='' ? "/images/no_picture.gif"  : $row['file_url'] ;
$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]['add_timea'] = local_date('d', $row['add_time']);
$arr[$idx]['add_timeb'] = local_date('Y-m', $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;

}


再加上 

$smarty->assign('class_articles_19', index_get_class_articles(19,6));   里面19是栏目ID  6是文章数量


在首页模板里面加上

 <!--{foreach from=$class_articles_21 item=article}-->
 <a href="{$article.url}" target="_blank">{$article.title|escape:html}</a> 
<!--{/foreach}-->

Copyright @ 2013-2021 元素模板 www.ys720.com All Rights Reserved. 版权所有 元素模板 www.ys720.com