根据文章分类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>
|