Ecshop首页调用指定分类下文章列表

我们在首页有时候需要单独调用某一个分类下的所有文章列表,按照下边方法没问题可以的,亲测有效噢。
首先我们要找到根目录的index.php文件
把这串代码粘贴进去,大概在140行左右区域位置,没有特别固定是在那行代码下边。


这串代码里的数字21是文章分类id后边的数字6是调用数量。如果要更换自己的分类前边数字21和后边那个数字21都要改下。
然后在index.php文件的最底部加上这串代码,切记一定要在?>这个符号前边。

$smarty->assign('class_articles_21', index_get_class_articles(21,6)); // 分类调用文章


接下来就好说了,找到我们模板首页文件,用下边这串代码调就可以拉,记住分类id21要改和上边一致噢。

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;
}

首页调用文章id看这个文章

<!--{foreach from=$class_articles_21 item=article}-->

<li><a href="{$article.url}" target="_blank"><!--{$article.short_title|truncate:15:true}--></a></li>

<!--{/foreach}-->

原文链接:https://www.um80.com/350.htm,转载请注明出处。

0
金秋上云特惠新人专享

评论0

本站所有素材,站长均亲自测试过,可放心使用,有什么问题联系我们!18091738064(微信)
没有账号? 注册  忘记密码?

社交账号快速登录

Copyright   ©2017-2024  U码80  陕ICP备17013443号-1  

陕公网安备 61032402000158号