PHPCMS调用多个栏目下文章的两个办法

第一种、直接写子栏目id ,用cat in

{pc: get sql="SELECT * from v9_news where status=99 and catid in(21,22,23,24,25)  thumb!='' order by id DESC" num="7" return="data"}
{loop $data $r}
      
  • url]}" title="{$r[title]}" target="_blank">{str_cut($r['title'],40)}({date('m-d',$r[inputtime])})

  • {/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}
            
  • [{$CATEGORYS[$r[catid]][catname]}]{str_cut($r['title'],40)}[{date('Y-m-d',$r[inputtime])}]

  • {/loop}
    {/pc}

    好处:只要写一个父栏目id, 自动取下级子栏目id
    缺点:循环父栏目下所有的子栏目id,如果某个子栏目的内容不想显示的话,不好实现

    你可能感兴趣的:(phpcms)