各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案

Str Tom,为分享PHP技术和解决方案,贡献一份自己的力量!
收藏本站(不迷路),每天更新好文章!
当前位置:首页 > CMS教程 > phpcms

phpcms_v9如何在首页显示或排除某些栏目subcat(0,0

管理员 2022-08-28
phpcms
297

 v9如何在首页显示或排除某些栏目subcat(0,0,0,$siteid)

通过以下红色部分的栏目id来控制显示哪些栏目,id根据实际情况后台查询,subcat函数看最后附件解释,以下修改代码:
V9显示哪些栏目的方法

  1. {loop subcat(6,0,0,$siteid) $r} 
  2.   {if $r['catid']==1||$r['catid']==2 } //显示哪些栏目 
  3.         {php $num++} 
  4.         <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}> 
  5.           <h5 class="title-1">{$r}<a href="{$r}" class="more">更多>></a></h5> 
  6.              <div class="content"> 
  7.              {pc:content  action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"
  8.              {loop $info $v} 
  9.               <p> 
  10.                <img src="{thumb($v,90,0)}" width="90" height="60"/> 
  11.                <strong><a   target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],28)}</a></strong>
  12. <br />{str_cut($v['description'],100)} 
  13.                 </p> 
  14.               {/loop} 
  15.               {/pc}                
  16.                 <div class="bk15 hr"></div> 
  17.                 {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"
  18.                 <ul class="list lh24 f14"> 
  19.                 {loop $info $v} 
  20.                  <li>·<a href="{$v['url']}" target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],40)}</a></li> 
  21.                 {/loop} 
  22.                 </ul> 
  23.                 {/pc} 
  24.             </div> 
  25.         </div> 
  26.         {if $num%2==0}<div class="bk10"></div>{/if} 
  27.   {/if} 
  28.   {/loop} 

V9排除某个栏目的方法

  1. {loop subcat(6,0,0,$siteid) $r} 
  2.           {if $r['catid']==3 }<?php continue; ?>{/if} //排除某个栏目 
  3.           {php $num++} 
  4.         <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}> 
  5.           <h5 class="title-1">{$r}<a href="{$r}" class="more">更多>></a></h5> 
  6.              <div class="content"> 
  7.              {pc:content  action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"
  8.              {loop $info $v} 
  9.               <p> 
  10.                <img src="{thumb($v,90,0)}" width="90" height="60"/> 
  11.                     <strong><a   target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],28)}</a></strong>
  12. <br />{str_cut($v['description'],100)} 
  13.                 </p> 
  14.               {/loop} 
  15.               {/pc}                
  16.                 <div class="bk15 hr"></div> 
  17.                 {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"
  18.                 <ul class="list lh24 f14"> 
  19.                 {loop $info $v} 
  20.                  <li>·<a href="{$v['url']}" target="_blank" title="{$v['title']}"{title_style($v)}>{str_cut($v['title'],40)}</a></li> 
  21.                 {/loop} 
  22.                 </ul> 
  23.                 {/pc} 
  24.             </div> 
  25.         </div> 
  26.         {if $num%2==0}<div class="bk10"></div>{/if} 
  27.   {/loop} 

{loop subcat(0,0,0,$siteid) $r}{/loop}函数解释:

{loop subcat(0,0,0,$siteid) $r}{/loop}
/**
* 获取子栏目
* @param $parentid 父级id
* @param $type 栏目类型 1为单网页类型,0为栏目类型;(查看phpcms的mysql数据库可以看到)
* @param $self 是否包含本身 0为不包含
* @param $siteid 站点id
*/
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;
}

相关推荐

扫码关注

qrcode

QQ交谈

回顶部