Home > php教程 > php手册 > body text

ECSHOP教程之调用分类文章,

WBOY
Release: 2016-06-13 08:56:01
Original
1110 people have browsed it

ECSHOP教程之调用分类文章,

这几天帮一个朋友弄一个商城,用的是ECSHOP,感觉ECSHOP功能确实够 强大,但是对于不懂程序的人来说,使用起来还是挺复杂,稍微做点修改就得大费周折,如果能像动易那样出一套标签库就好了。

比如深蓝使用的时候需要按分类调用一下文章,这是一个很常见的功能,可以官方并没有提供,只好自己想办法,最后终于找到了办法。请看一下ECSHOP教程

具体实现方法:
举例如首页调用方法:
1、先打开index.php文件找到以下代码:

$smarty->assign('new_articles', index_get_new_articles()); // 最新文章
Copy after login



在它下面增加以下:

//调用方法

$smarty->assign('class_articles_4', index_get_class_articles(4,6)); // 分类调用文章
//调用多个就修改传进去的参数,以及模板接收的变量,其中上面的4就是文章分类ID,其中6是调用数量
$smarty->assign('class_articles_5', index_get_class_articles(5,6)); // 分类调用文章
$smarty->assign('class_articles_6', index_get_class_articles(6,6)); // 分类调用文章
$smarty->assign('class_articles_7', index_get_class_articles(7,6)); // 分类调用文章
$smarty->assign('class_articles_8', index_get_class_articles(8,6)); // 分类调用文章
Copy after login

//在最后?>这个之前增加以下函数



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;
}
Copy after login



2、第二步是在index.dwt模板想调用的地方增加以下代码,(注:以下调上面设置里的分类ID为8的文章列表):

 



按以上方法调用成功。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!