phpcms首页如何只显示指定栏目
下面的代码通过栏目id来控制显示哪些栏目,id根据实际情况后台查询,subcat函数看最后附件解释,以下修改代码:
{loop subcat(0,0,0,$siteid) $r} {if $r['catid']==1||$r['catid']==2 } //显示哪些栏目 {php $num++} <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}> <h5 class="title-1">{$r}<a href="{$r}" class="more">更多>></a></h5> <div class="content"> {pc:content action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"} {loop $info $v} <p> @@##@@ <strong><a target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],28)}</a></strong><br />{str_cut($v['description'],100)} </p> {/loop} {/pc} <div class="bk15 hr"></div> {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"} <ul class="list lh24 f14"> {loop $info $v} <li>·<a href="{$v['url']}" target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],40)}</a></li> {/loop} </ul> {/pc} </div> </div> {if $num%2==0}<div class="bk10"></div>{/if} {/if} {/loop}
除了指定特定的栏目,我们也可以使用排除的方式,显示特定的栏目
V9排除某个栏目的方法
{loop subcat(0,0,0,$siteid) $r} {if $r['catid']==3 }<?php continue; ?>{/if} //排除某个栏目 {php $num++} <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}> <h5 class="title-1">{$r}<a href="{$r}" class="more">更多>></a></h5> <div class="content"> {pc:content action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"} {loop $info $v} <p> @@##@@ <strong><a target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],28)}</a></strong><br />{str_cut($v['description'],100)} </p> {/loop} {/pc} <div class="bk15 hr"></div> {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"} <ul class="list lh24 f14"> {loop $info $v} <li>·<a href="{$v['url']}" target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],40)}</a></li> {/loop} </ul> {/pc} </div> </div> {if $num%2==0}<div class="bk10"></div>{/if} {/loop}
{loop subcat(0,0,0,$siteid) $r}{/loop}函数解释:
立即学习“PHP免费学习笔记(深入)”;
function subcat($parentid = NULL, $type = NULL,$self = '0', $siteid = '') { if (empty($siteid)) $siteid = get_siteid(); $category = getcache('category_content_'.$siteid,'commons'); foreach($category as $id=>$cat) { if($cat['siteid'] == $siteid && ($parentid === NULL || $cat['parentid'] == $parentid) && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat; if($self == 1 && $cat['catid'] == $parentid && !$cat['child']) $subcat[$id] = $cat; } return $subcat; }
PHP中文网,大量的免费PHPCMS教程,欢迎在线学习!
以上就是phpcms首页如何只显示指定栏目的详细内容,更多请关注本网内其它相关文章!