phpcms v9 常用get标签
[ 2012-05-30 23:31:08 | 作者: admin ]
PhpCms V9调用指定栏目子栏目文章的两种方法
第一种、直接写子栏目id ,用cat in
{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 title=”{$r[title]}” href=”{$r[url]}” target=”_blank”>{str_cut($r['title'],40)}({date(‘m-d’,$r[inputtime])})</a></li>
{/loop}
{/pc}
这种方法的好处:可以想取那个栏目可以自定义
缺点:要写多个id,后台增加了栏目的话得再把id写进去
第二种,根据父栏目id,如上面的21,22,23,24,25都是 15下面的子栏目,可以这样写:
{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 title=”{$r[title]}” href=”{$r[url]}” target=”_blank”>{str_cut($r['title'],40)}</a></strong><em>[{date('Y-m-d',$r[inputtime])}]</em></span></li>
{/loop}
{/pc}
好处:只要写一个父栏目id,自动取下级子栏目id
缺点:循环父栏目下所有的子栏目id,如果某个子栏目的内容不想显示的话,不好实现
两种方法各有利弊,视情况选之。
====================================================
1、全站多模型联合调用最新文章
{pc:get
sql="SELECT id,url,title,status,inputtime from v9_news WHERE status=99
UNION SELECT id,url,title,status,inputtime from v9_picture WHERE status=99
UNION SELECT id,url,title,status,inputtime from v9_flashgame WHERE status=99
ORDER BY inputtime DESC" num="10"}
{loop $data $r}
<a href="{$r[url]}" title="{$r[title]}" target="_blank">{$r[title]}</a>
{/loop}
{/pc}
多个栏目调用
{pc:get sql="SELECT `n`.`inputtime`,`n`.`url`,`n`.`title`,`c`.`catname`,`c`.`url` as `c_url` FROM `v9_news` as `n` left join `v9_category` as `c` on `n`.`catid` = `c`.`catid` where `c`.`catid` in (18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40) order by `n`.`id` desc" num="10" return="data"}
{loop $data $key $val}{date('Y-m-d H:i:s',$val[inputtime])}[{$val[catname]}] {$val[title]}
{/loop}
{/pc}
2、热门搜索
{pc:get sql="select keyword from v9_search_keyword" orderby="searchnums desc" num="5" cache="3600"}
{loop $data $r}
<a href="{APP_PATH}index.php?m=search&c=index&a=init&typeid=1&siteid=1&q={$r[keyword]}" target="_blank">{$r[keyword]}</a>
{/loop}
{/pc}
3、热门关键词调用
{pc:get sql="select keyword from v9_search_keyword" orderby="searchnums desc" num="5" cache="3600"}
{loop $data $r}
<a href="{APP_PATH}index.php?m=search&c=index&a=init&typeid=1&siteid=1&q={$r[keyword]}" target="_blank">{$r[keyword]}</a>
{/loop}
{/pc}
4、get 分页肯定能用
{get sql="SELECT contentid,catid,title,style,thumb,keywords,description,userid,updatetime,islink,inputtime,url FROM `content` WHERE status=99 AND `catid` = $catid ORDER BY contentid DESC" rows="8" page="$page"catid="$catid"}
<li><a href="{$r[url]}"><img src="{$r[thumb]}" width="125" height="200" border="0" alt="{$r[title]}" /></a><br /><a href="{$r[url]}" title="{$r[title]}" target="_blank">{str_cut($r[title], 27,'')}</a></li>
{/get}
{$pages}
5、在首页某模型所有栏目最新文章调用带栏目名称
{pc:get sql="select * from v9_convert_news where status=99 order by id desc" num="11"}
{loop $data $v}
<li style="text-align:center;"><a href="{$CATEGORYS[$v[catid]][url]}" style="font-size:12px; color:#F30">{str_cut($CATEGORYS[$v[catid]][catname],45,'...')}</a></li>
<li style="width:280px;">
| <a href="{$v['url']}" title="{$r[title]}" target="_blank">{str_cut($v[title],90)}</a></li>
{/loop}
{/pc}
第一种、直接写子栏目id ,用cat in
{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 title=”{$r[title]}” href=”{$r[url]}” target=”_blank”>{str_cut($r['title'],40)}({date(‘m-d’,$r[inputtime])})</a></li>
{/loop}
{/pc}
这种方法的好处:可以想取那个栏目可以自定义
缺点:要写多个id,后台增加了栏目的话得再把id写进去
第二种,根据父栏目id,如上面的21,22,23,24,25都是 15下面的子栏目,可以这样写:
{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 title=”{$r[title]}” href=”{$r[url]}” target=”_blank”>{str_cut($r['title'],40)}</a></strong><em>[{date('Y-m-d',$r[inputtime])}]</em></span></li>
{/loop}
{/pc}
好处:只要写一个父栏目id,自动取下级子栏目id
缺点:循环父栏目下所有的子栏目id,如果某个子栏目的内容不想显示的话,不好实现
两种方法各有利弊,视情况选之。
====================================================
1、全站多模型联合调用最新文章
{pc:get
sql="SELECT id,url,title,status,inputtime from v9_news WHERE status=99
UNION SELECT id,url,title,status,inputtime from v9_picture WHERE status=99
UNION SELECT id,url,title,status,inputtime from v9_flashgame WHERE status=99
ORDER BY inputtime DESC" num="10"}
{loop $data $r}
<a href="{$r[url]}" title="{$r[title]}" target="_blank">{$r[title]}</a>
{/loop}
{/pc}
多个栏目调用
{pc:get sql="SELECT `n`.`inputtime`,`n`.`url`,`n`.`title`,`c`.`catname`,`c`.`url` as `c_url` FROM `v9_news` as `n` left join `v9_category` as `c` on `n`.`catid` = `c`.`catid` where `c`.`catid` in (18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40) order by `n`.`id` desc" num="10" return="data"}
{loop $data $key $val}{date('Y-m-d H:i:s',$val[inputtime])}[{$val[catname]}] {$val[title]}
{/loop}
{/pc}
2、热门搜索
{pc:get sql="select keyword from v9_search_keyword" orderby="searchnums desc" num="5" cache="3600"}
{loop $data $r}
<a href="{APP_PATH}index.php?m=search&c=index&a=init&typeid=1&siteid=1&q={$r[keyword]}" target="_blank">{$r[keyword]}</a>
{/loop}
{/pc}
3、热门关键词调用
{pc:get sql="select keyword from v9_search_keyword" orderby="searchnums desc" num="5" cache="3600"}
{loop $data $r}
<a href="{APP_PATH}index.php?m=search&c=index&a=init&typeid=1&siteid=1&q={$r[keyword]}" target="_blank">{$r[keyword]}</a>
{/loop}
{/pc}
4、get 分页肯定能用
{get sql="SELECT contentid,catid,title,style,thumb,keywords,description,userid,updatetime,islink,inputtime,url FROM `content` WHERE status=99 AND `catid` = $catid ORDER BY contentid DESC" rows="8" page="$page"catid="$catid"}
<li><a href="{$r[url]}"><img src="{$r[thumb]}" width="125" height="200" border="0" alt="{$r[title]}" /></a><br /><a href="{$r[url]}" title="{$r[title]}" target="_blank">{str_cut($r[title], 27,'')}</a></li>
{/get}
{$pages}
5、在首页某模型所有栏目最新文章调用带栏目名称
{pc:get sql="select * from v9_convert_news where status=99 order by id desc" num="11"}
{loop $data $v}
<li style="text-align:center;"><a href="{$CATEGORYS[$v[catid]][url]}" style="font-size:12px; color:#F30">{str_cut($CATEGORYS[$v[catid]][catname],45,'...')}</a></li>
<li style="width:280px;">
| <a href="{$v['url']}" title="{$r[title]}" target="_blank">{str_cut($v[title],90)}</a></li>
{/loop}
{/pc}
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1828
这篇日志没有评论。
此日志不可发表评论。