ecshop根据分类id调文章

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



根据文章分类id调用该分类下的文章

1、打开includes下 init.php

末尾处增加下列代码——可根据实际情况,增删里面的查询字段。

function index_get_class_articles($cat_aid, $cat_num)

{

$sql = "SELECT article_id, title,open_type,cat_id,content,file_url,add_time,description 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]['content'] = $row['content'];

$arr[$idx]['short_content'] = sub_str($row['content'],33);

$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']));

$arr[$idx]['file_url'] = trim($row['file_url']);//图片路径

$arr[$idx]['description'] = $row['description'];

$arr[$idx]['short_description'] = sub_str($row['description'],15);

}

return $arr;

}


2、在调用该文章的页面添加代码
<?php
$GLOBALS['smarty']->assign('articles',index_get_class_articles(14, 6));<!--14代表文章分类id,6为数量-->
?>

<UL id="">
<!--{foreach from=$articles item=art name=art}-->
<li><a title="{$art.title}" target="_blank" href="{$art.url}">{$art.short_title}</a></li>
<!--{/foreach}-->
</UL>


试例商城:手绘油画

回答:
我照这步骤走,怎么实现不了,引用后前台出现$GLOBALS['smarty']->assign('articles',index_get_class_articles(14, 6));

我是在分类页里面引用的,category.dwt,请问哪有问题

很好 很强大啊 !! 化妆品商城真棒啊

好教程.收下了