PHPCMS点击排行显示相关文章(v9)

示例代码如下,

{pc:content action="hits" catid="$catid" num="2" order="views DESC"}
   {loop $data $key $r}
   <div class="hotNews">
     <div class="space01"></div>
     <h2><a href="{$r[url]}" target="_blank" title="{$r[title]}"{title_style($r[style])}>{$r[title]}</a></h2>
     {pc:get sql="SELECT relation FROM v9_news_data a WHERE a.id=$r[id]" return="relation"} 
     {loop $relation $v}
     {php $ins = implode(',', explode("|", $v[relation]));}   
     {pc:get sql="SELECT * FROM v9_news a WHERE a.id in ($ins)" return="more"} 
     {loop $more $v2}
     <h3><a href="{$v2[url]}" target="_blank" title="{$v2[title]}"{title_style($v2[style])}>{$v2[title]}</a></h3>
     {/loop}
     {/pc}
     {/loop}
   </div>
   {/loop}
  {/pc} 
   

代码分析

1.获取当前文章的relation字段(记录了相关文章的id集合,例如5|6|7|8),返回的结果是列表,其实返回的数据行就一行

{pc:get sql="SELECT relation FROM v9_news_data a WHERE a.id=$r[id]" return="relation"}

2.将relaiton字段的值修改为sql需要的格式

{php $ins = implode(',', explode("|", $v[relation]));}

例如,可将5|6|7|8变成5,6,7,8

3.获取所有的相关文章

{pc:get sql="SELECT * FROM v9_news a WHERE a.id in ($ins)" return="more"}

你可能感兴趣的:(style,id,Cursor,Direction,Silver)