1、在需要使用此功能的PHP页面里最后的?>前面添加以下代码,现在以article.php为例子
/** ecshop119.com
* 获得指定分类ID、文章类型、指定数量、排序规则的文章列表。
* @access private
* @return array
* @cat_id 文章分类ID 0代表显示所有分类的以下条件文章
* @list_type 文章列表类型 0 普通 1置顶 2头条 3推荐 4热门
* @list_num 文章列表数量 默认10条新闻,可不填写
* @list_order 文章列表排序 默认按照最新添加的排序,可不填写
*/
function
get_class_list_articles(
$cat_id
=
'0'
,
$list_type
=
'0'
,
$list_num
=
'10'
,
$list_order
=
'add_time DESC'
)
{
$sql
=
'SELECT article_id, title, add_time, file_url, open_type '
.
' FROM '
.
$GLOBALS
[
'ecs'
]->table(
'article'
) .
' WHERE '
;
if
(
$cat_id
!=
'0'
){
$sql
=
$sql
.
' cat_id = '
.
$cat_id
.
' and '
;
}
$sql
=
$sql
.
' article_type='
.
$list_type
.
' ORDER BY '
.
$list_order
.
' LIMIT '
.
$list_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
][
'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'
]);
}
return
$arr
;
}
您是不是很疑惑,ECSHOP只有普通及置顶的文章,哪来的其它类型的文章哦,至于这个你就得看下我写的另外一篇文章了。
2、继续在此article.php文件里调用显示的代码里添加以下代码:
$smarty
->assign(
'hot_goods'
, get_recommend_goods(
'hot'
));
// 热点文章
$smarty
->assign(
'list_articles15'
, get_class_list_articles(
'15'
,
'0'
,
'6'
,
'add_time ASC'
));
//15为文章分类ID,别告诉我你不知道怎么看;0代表普通的文章;6是文章显示数量;add_time ASC代表是按照添加时间的先后顺序显示
3、在要显示此内容的article.dwt模板文件里添加以下代码:
<!--{
foreach
from=
$list_articles15
item=article}-->
<li><a title=
"{$article.title|escape:html}"
href=
"{$article.url}"
>{
$article
.title}</a></li>
<!--{/
foreach
}-->