IT技术互动交流平台

phpcms2008 列表动态调取点击量

作者:阿杜博客  发布日期:2013-07-31 18:40:20

直接步入正题:

1.修改文件 /templates/default/phpcms/list.html

 

<?php $i=1;?>
{get sql="SELECT a.contentid as id,a.title as title,a.updatetime as updatetime,a.url as url FROM `lwcms_content` as a  WHERE  a.status=99 and catid = $catid ORDER BY a.updatetime DESC" rows="20" page="$page"}

  <tr>
    <td height="30" align="center"><?php echo $i;?></td>
    <td> 
 <?php
 if($catid==412||$catid==413){
 ?>
 <a looyu_bound="1" href="{$r['url']}" target="_blank" title="{$r['title']}">{$r['title']}</a>
 <?}else{?>
 <a looyu_bound="1" href="{str_replace('html/','',$r['url'])}" target="_blank" title="{$r['title']}">{$r['title']}</a>
 <?}?>
 
 </td>
    <td align="center">&nbsp;   &nbsp; </td>
    <td align="center">{date('Y-m-d',$r['updatetime'])}</td>
    <td align="center" id="hits{$r[id]}">0</td>
 <?php
  if($i!=1){
   $d=",";
  }
  $ids.=$d.$r[id];
 ?>
  <!-- {$r['hits']}1 -->
  </tr>
  <?php $i++;?>
 {/get}
</tbody></table>
<script language="JavaScript" src="count_list.php?ids={$ids}&modelid={$modelid}"></script>
<div style="text-align:right;margin-top:10px;">
<?php
//检测url规则
//$sql_rule  = "select urlrule from lwcms_urlrule where urlruleid=".$category_urlruleid;
//$query_rule= $db->get_one($sql_rule);
//$temp = explode("|",$query_rule['urlrule']);
//$rule = $temp[count($temp)-1];
$sql = "SELECT contentid FROM `lwcms_content` where catid = $catid and status =99";
$query = $db->query($sql);
$nums  = $db->num_rows($query);
$all   = ceil($nums/20);
$page_up = ($page-1)<=0?1:($page-1);
$page_next = ($page+1)>=$all?$all:($page+1);
$first = "/column-".$catid."_1.html";
$up    = "/column-".$catid."_".$page_up.".html";
$next  = "/column-".$catid."_".$page_next.".html";
$last  = "/column-".$catid."_".$all.".html";
//$first = str_replace('col','1',$rule);
//$up    = str_replace($page,$page_up,$rule);
//$next  = str_replace($page,$page_next,$rule);
//$last  = str_replace($page,$all,$rule);
?>
总数:<b><?php echo $nums?></b>
<a href="{$first}">首页</a>&nbsp;
<a href="<?php echo $up;?>">上一页</a>&nbsp;
<a href="<?php echo $next;?>">下一页</a>&nbsp;
<a href="<?php echo $last;?>">尾页</a>&nbsp;
页次:<b><font color="red"><?php echo $page;?></font>/<?php echo $all;?></b>
</div>

已上是之前同事写的,我就直接复制过来了,红色部分为新加的,大家看思路就好。

2、创建count_list.php

 

<?php
require dirname(__FILE__).'/include/common.inc.php';
require_once 'admin/content.class.php';
/**
* 点击统计
*/
$ids=$_GET['ids'];
$data=explode(",", $ids);
$idsstr = '';
for($i=0;$i<count($data);$i++){
 if($i!='0'){
  $d = ",";
 }
 $idsstr.=$d.intval($data[$i]);
}
if($_GET['modelid']) {
  $c = new content();
  $data = $c->gethits($idsstr);

  foreach($data as $k => $v){
          echo "\$('#hits".$v['contentid']."').html('".$v['hits']."');\n\r";
  }

}
?>

3. 修改include/admin/content.class.php

增加方法:

 

function gethits($contentid)
 { global $db;
  if(empty($contentid)) return false;
  $r = $db->select("SELECT hits,contentid FROM `$this->table_count` WHERE `contentid` in ($contentid)");
  if(!$r) return false;
  return $r;
 }

只要做已上三步即可解决问题。

注: 别忘了在单页也加一下如下这段代码:

<script language="JavaScript" src="count.php?contentid={$contentid}"></script>

做完以上步骤,后台更新即可。

 

Tag标签: phpcms   调取点击量  
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规