当前位置:网站首页>phpcms v9后台增加阅读量字段,可任意修改阅读量
phpcms v9后台增加阅读量字段,可任意修改阅读量
2022-06-26 08:38:00 【cms小程序插件【官方】】
由于phpcms的内容表和点击量是分开的,所以官方并没有给后台设置控制阅读量的字段,有时候我们需要自定义阅读量,这就需要简单的二次开发了。
(1)找到phpcms\modules\content\templates文件夹的content_edit.tpl.php和content_add.tpl.php两个文件
content_edit.tpl.php大概80行,找到如下代码:
- </tbody></table>
在这行代码之前加入如下代码:
- <tr>
- <th width="80">阅读量</th>
- <td><input type='text' name='info[views]' id='views' value='<?php echo $views;?>' size='3' class='input-text'> (默认随机生成)</td>
- </tr>
同样content_add.tpl.php大概82行,找到如下代码:
</tbody></table> 在这之前加入同样的代码
- <tr>
- <th width="80">阅读量</th>
- <td><input type='text' name='info[views]' id='views' value='<?php echo $views;?>' size='3' class='input-text'> (默认随机生成)</td>
- </tr>
(2)找到phpcms\model\content_model.class.php找到大概107行:
- //添加统计
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$modelid.'-'.$id;
- $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'updatetime'=>SYS_TIME));
改成:
- //添加统计
- $views = $data['views'];
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$modelid.'-'.$id;
- $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'views'=>$views,'updatetime'=>SYS_TIME));
然后301行找到代码:
- //调用 update
在这之前加入代码:
- //添加统计
- $views = $data['views'];
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$this->modelid.'-'.$id;
- $this->hits_db->update(array('views' => $views),array('hitsid' => $hitsid));
(3)找到\phpcms\modules\content\content.php文件
大概163行找到代码:
- param::set_cookie('module', 'content');
在这下边新增一个生成随机点击量的代码:
- $views = rand(10,999);/*生成随机点击数*/
然后找到代码大概250行:
- $forminfos = $content_form->get($data);
- $formValidator = $content_form->formValidator;
在这后边新增代码:
- /*加载点击*/
- $hitsid = "c-".$modelid."-".$id;
- $db_hits = pc_base::load_model('hits_model');//引入hits
- $view = $db_hits ->get_one(array('hitsid' => $hitsid),'views');
- $views = $view['views'];
加完之后,更新缓存,你可以尝试一下新增或者修改文章,看看是否可以任意修改阅读量!
边栏推荐
- Tensorboard
- How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?
- Detailed explanation of self attention & transformer
- Exploration of webots and ROS joint simulation (II): model import
- Playing card image segmentation
- Yolov5进阶之二安装labelImg
- 9. code generation
- Isinstance() function usage
- 20220623 getting started with Adobe Illustrator
- Leetcode notes: binary search simple advanced
猜你喜欢

Simulation of parallel structure using webots

Isinstance() function usage

Polka lines code recurrence

Autoregressive model of Lantern Festival

Selenium 搭建 Cookies池 绕过验证反爬登录

多台三菱PLC如何实现无线以太网高速通讯?

XSS 跨站脚本攻击

Euler function: find the number of numbers less than or equal to N and coprime with n

WBC learning notes (I): manually push WBC formula

利用无线技术实现分散传感器信号远程集中控制
随机推荐
Using MySQL and Qt5 to develop takeout management system (I): environment configuration
Simulation of parallel structure using webots
Formula understanding in quadruped control
Fast construction of neural network
Detailed explanation of self attention & transformer
Relationship extraction -- casrel
Two ways to realize time format printing
Steps for ROS to introduce opencv (for cmakelist)
Data warehouse (1) what is data warehouse and what are the characteristics of data warehouse
Data warehouse (3) star model and dimension modeling of data warehouse modeling
如何利用最少的钱,快速打开淘宝流量入口?
Is it safe to open an account in flush,
深度学习论文阅读目标检测篇(七)中文版:YOLOv4《Optimal Speed and Accuracy of Object Detection》
Zlmediakit push pull flow test
隐藏式列表菜单以及窗口转换在Selenium 中的应用
Bezier curve learning
读书笔记:SQL 查询中的SQL*Plus 替换变量(DEFINE变量)和参数
Sqoop merge usage
Pandas vs. SQL 1_ nanyangjx
Transformers loading Roberta to implement sequence annotation task