ECShop模板如何调出文章分类

lib_article.php中添加

function get_cat_articles1($cat_id, $page = 1, $size = 20 ,$requirement=”){ //取出所有非0的文章 if ($cat_id == ‘-1’) { $cat_str = ‘cat_id > 0’; } else { $cat_str = get_article_children($cat_id); } //增加搜索条件,,如果有搜索内容就进行搜索 if ($requirement != ”) { $sql = ‘SELECT article_id, title, author, add_time, file_url, open_type’ . ‘ FROM ‘ .$GLOBALS[‘ecs’]->table(‘article’) . ‘ inner join ecs_article_cat on ecs_article.cat_id=ecs_article_cat.cat_id and ecs_article_cat.cat_id=’.$cat_id.’ WHERE is_open = 1 AND title like \’%’ . $requirement . ‘%’ ‘ ; } else { $sql = ‘SELECT cat_name, article_id, title, author, add_time, file_url, open_type’ . ‘ FROM ‘ .$GLOBALS[‘ecs’]->table(‘article’) . ‘ inner join ecs_article_cat on ecs_article.cat_id=ecs_article_cat.cat_id and ecs_article_cat.cat_id=’.$cat_id; }

$res = $GLOBALS[‘db’]->selectLimit($sql, $size, ($page-1) * $size); $arr = array(); if ($res) { while ($row = $GLOBALS[‘db’]->fetchRow($res)) { $article_id = $row[‘article_id’];

$arr[$article_id][‘id’] = $article_id; $arr[$article_id][‘title’] = $row[‘title’]; $arr[$article_id][‘short_title’] = $GLOBALS[‘_CFG’][‘article_title_length’] > 0 ? sub_str($row[‘title’], $GLOBALS[‘_CFG’][‘article_title_length’]) : $row[‘title’]; } } return $arr;}

添加article_list.php

在article_list.php中添加

如果是按照id显示一条 $smarty->assign(‘artciles_list2’, get_cat_articles1($cat_id, $page, $size ,$keywords));$smarty->assign(‘ar2’,get_catname_by_catid($cat_id));如果显示全部id必须全写上 比如:$smarty->assign(‘artciles_list2’, get_cat_articles1(2, $page, $size ,$keywords));$smarty->assign(‘ar2’,get_catname_by_catid(2));

$smarty->assign(‘artciles_list3’, get_cat_articles1(3, $page, $size ,$keywords));$smarty->assign(‘ar3’,get_catname_by_catid(3));2,3是id $size是显示几条 如果直接写$size 默认代表10条

最下面添加function get_catname_by_catid($cat_id){$sql="select cat_name from ecs_article_cat where cat_id=’$cat_id’";$row=$GLOBALS[‘db’]->getRow($sql);return $row; }

在article_list.dwt中添加如果想按照id显示一条<table border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd"> <tr> <td bgcolor="#ffffff"> <!–{if $ar2.cat_name}–> {$ar2.cat_name} <!–{/if}–> </td> <tr> <!– {foreach from=$artciles_list2 item=article} –> <tr> <td bgcolor="#ffffff"><a href="{$article.url}" title="{$article.title|escape:html}" class="f6">{$article.short_title}</a></td> </tr> <!– {/foreach} –> </table>

诚实是人生绝妙的法宝。虽然对人诚实,

ECShop模板如何调出文章分类

相关文章:

你感兴趣的文章:

标签云: