第一种、直接写子栏目id ,用cat in
1
2
3
4
5
|
{pc:get sql=
"SELECT * from v9_news where status=99 and catid in(21,22,23,24,25) order by id DESC"
num=
"7"
return
=
"data"
}
{loop
$data
$r
}
<li><a href=
"{$r[url]}"
title=
"{$r[title]}"
target=
"_blank"
>{str_cut(
$r
[
'title'
],40)}({
date
(
'm-d'
,
$r
[inputtime])})</span></a></li>
{/loop}
{/pc}
|
这种方法的好处:可以想取那个栏目可以自定义
缺点:要写多个id,后台增加了栏目的话得再把id写进去
第二种,根据父栏目id,如上面的21,22,23,24,25都是 15下面的子栏目,可以这样写:
1
2
3
4
5
6
7
8
9
|
{loop subcat(15)
$k
$v
}
{php
$subcatid
[] =
$k
;}
{/loop}
{php
$subcatid
= implode(
','
,
$subcatid
);}
{pc:get sql=
"SELECT * from v9_news where status=99 and catid in ($subcatid) order by id DESC"
num=
"7"
return
=
"data"
}
{loop
$data
$r
}
<li><span><strong><a href=
"{$CATEGORYS[$r[catid]][url]}"
>[{
$CATEGORYS
[
$r
[catid]][catname]}]</a><a href=
"{$r[url]}"
title=
"{$r[title]}"
target=
"_blank"
>{str_cut(
$r
[
'title'
],40)}</a></strong><em>[{
date
(
'Y-m-d'
,
$r
[inputtime])}]</em></span></li>
{/loop}
{/pc}
|
好处:只要写一个父栏目id,自动取下级子栏目id
缺点:循环父栏目下所有的子栏目id,如果某个子栏目的内容不想显示的话,不好实现
本文转自 gutaotao1989 51CTO博客,原文链接:http://blog.51cto.com/taoyouth/1588253