Home  >  Article  >  Backend Development  >  PhpCms V9调用指定栏目子栏目稿子的两种方法

PhpCms V9调用指定栏目子栏目稿子的两种方法

WBOY
WBOYOriginal
2016-06-13 13:20:02850browse

PhpCms V9调用指定栏目子栏目文章的两种方法

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}
? ?? ?

  • 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,如果某个子栏目的内容不想显示的话,不好实现

    两种方法各有利弊,视情况选之。

    ?

    http://www.veryhuo.com/a/view/30459.html

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn