首页 > Web开发 > 详细

PHPCMS V9 按浏览次数排行调用文章

时间:2015-12-14 19:10:51      阅读:324      评论:0      收藏:0      [点我收藏+]

频道总排行调用方法

<div class="box">
    <h5 class="title-2">频道总排行</h5>
    {pc:get sql="select a.id,a.title,a.url,a.catid,b.hitsid,b.views from v9_news a left join v9_hits b on a.id=substring(b.hitsid,5) where a.catid in ($arrchildid) order by b.views desc" num="10" cache="3600"}
    <ul class="content digg">
        {loop $data $r}
            <li> <a href="{$r[url]}" title="{$r[title]}"  target="_blank">{str_cut($r[title],36,‘...‘)}</a></li>
        {/loop}
    </ul>
    {/pc}
</div>

频道月排行调用方法

<div class="box">
    <h5 class="title-2">频道总排行</h5>
    {pc:get sql="select a.id,a.title,a.url,a.catid,b.hitsid,b.views from v9_news a left join v9_hits b on a.id=substring(b.hitsid,5) where a.catid in ($arrchildid) order by b.views desc" num="10" cache="3600"}
    <ul class="content digg">
        {loop $data $r}
            <li> <a href="{$r[url]}" title="{$r[title]}"  target="_blank">{str_cut($r[title],36,‘...‘)}</a></li>
        {/loop}
    </ul>
    {/pc}
</div>

调用全站所有文章排行的方法:

<div class="idxTopApps contents">
<ul class="indexIcns">
{pc:get sql="SELECT a.id,a.url,a.thumb,a.status,b.hitsid,b.views FROM v9_download a, v9_hits b WHERE a.status=99 and a.id=substring(b.hitsid,5) ORDER BY b.views DESC" num="6"}
{loop $data $r}
<li><a href="{$r[‘url‘]}"><img src="{$r[‘thumb‘]}" /></a></li>
{/loop}
{/pc}
</ul>
</div>

可以看到“substring(b.hitsid,5)”是截取hitsid字段,从左往右数第5个字符串,即“c-2-5”从左往右数,1个“c”,1个“2”,2个“-”,第5个字符就是“5”,截取后只剩下了第2个“-”后的id,到达了最终提取id的目的。当然,其中我还加入了另一个条件“status=99”,这个表示已经审核通过的文章,这个可有可无。

PHPCMS V9 按浏览次数排行调用文章

原文:http://taoyouth.blog.51cto.com/2793776/1722953

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!