打开lib_article.php添加以下代码
01.
function
get_cat_articles1(
$cat_id
,
$page
= 1,
$size
= 20 ,
$requirement
=
''
)
02.
{
03.
//取出所有非0的文章
04.
if
(
$cat_id
==
'-1'
)
05.
{
06.
$cat_str
=
'cat_id > 0'
;
07.
}
08.
else
09.
{
10.
$cat_str
= get_article_children(
$cat_id
);
11.
}
12.
//增加搜索条件,如果有搜索内容就进行搜索
13.
if
(
$requirement
!=
''
)
14.
{
15.
$sql
=
'SELECT article_id, title, author, add_time, file_url, open_type'
.
16.
' FROM '
.
$GLOBALS
[
'ecs'
]->table(
'article'
) .
17.
' 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
.
'%\' '
;
18.
}
19.
else
20.
{
21.
$sql
=
'SELECT cat_name, article_id, title, author, add_time, file_url, open_type'
.
22.
' FROM '
.
$GLOBALS
[
'ecs'
]->table(
'article'
) .
23.
' inner join ecs_article_cat on ecs_article.cat_id=ecs_article_cat.cat_id and ecs_article_cat.cat_id='
.
$cat_id
;
24.
}
25.
$res
=
$GLOBALS
[
'db'
]->selectLimit(
$sql
,
$size
, (
$page
-1) *
$size
);
26.
$arr
=
array
();
27.
if
(
$res
)
28.
{
29.
while
(
$row
=
$GLOBALS
[
'db'
]->fetchRow(
$res
))
30.
{
31.
$article_id
=
$row
[
'article_id'
];
32.
$arr
[
$article_id
][
'id'
] =
$article_id
;
33.
$arr
[
$article_id
][
'title'
] =
$row
[
'title'
];
34.
$arr
[
$article_id
][
'short_title'
] =
$GLOBALS
[
'_CFG'
][
'article_title_length'
] > 0 ? sub_str(
$row
[
'title'
],
$GLOBALS
[
'_CFG'
][
'article_title_length'
]) :
$row
[
'title'
];
35.
}
36.
}
37.
return
$arr
;
38.
}
打开article_list.php添加以下代码
如果是按照id显示一条
1.
$smarty
->assign(
'artciles_list2'
, get_cat_articles1(
$cat_id
,
$page
,
$size
,
$keywords
));
2.
$smarty
->assign(
'ar2'
,get_catname_by_catid(
$cat_id
));
如果显示全部id必须全写上 比如:
1.
$smarty
->assign(
'artciles_list2'
, get_cat_articles1(2,
$page
,
$size
,
$keywords
));
2.
$smarty
->assign(
'ar2'
,get_catname_by_catid(2));
3.
$smarty
->assign(
'artciles_list3'
, get_cat_articles1(3,
$page
,
$size
,
$keywords
));
4.
$smarty
->assign(
'ar3'
,get_catname_by_catid(3));
2,3是id $size是显示几条 如果直接写$size 默认代表10条
最下面添加
1.
function
get_catname_by_catid(
$cat_id
)
2.
{
3.
$sql
=
"select cat_name from ecs_article_cat where cat_id='$cat_id'"
;
4.
$row
=
$GLOBALS
[
'db'
]->getRow(
$sql
);
5.
return
$row
;
6.
}
在article_list.dwt中添加
如果想按照id显示一条
01.
<
table
border
=
"0"
cellpadding
=
"5"
cellspacing
=
"1"
bgcolor
=
"#dddddd"
>
02.
<
tr
>
03.
<
td
bgcolor
=
"#ffffff"
>
04.
<!--{if $ar2.cat_name}-->
05.
{$ar2.cat_name}
06.
<!--{/if}-->
07.
</
td
>
08.
<
tr
>
09.
<!-- {foreach from=$artciles_list2 item=article} -->
10.
<
tr
>
11.
<
td
bgcolor
=
"#ffffff"
><
a
href
=
"{$article.url}"
title
=
"{$article.title|escape:html}"
class
=
"f6"
>{$article.short_title}</
a
></
td
>
12.
</
tr
>
13.
<!-- {/foreach} -->
14.
</
table
>
声明:
1、本站所发布的资源均从互联网上收集整理而来,仅供学习和测试使用
2、请在下载资源后24小时内将资源从您的电脑上删除,非法使用资源所发生的一切问题与本站无关
3、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务
4、若本站收集的资源无意侵犯了您的合法权益,请联系我们予以删除
5、本站不提供任何实质性的付费和支付项目,所有需要点数下载的项目均为赞助费用或者线下劳务费用
6、如果你注册本站用户或下载本站资源,则认为你认可并同意以上声明