当前位置:网站首页>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'];
加完之后,更新缓存,你可以尝试一下新增或者修改文章,看看是否可以任意修改阅读量!
边栏推荐
- 隐藏式列表菜单以及窗口转换在Selenium 中的应用
- Convert verification code image to tfrecord file
- Parameter understanding of quad dataloader in yolov5
- Tensorboard
- Matlab function foundation (directly abandon version)
- Torch model to tensorflow
- [resolved]setonnavigationitemselectedlistener() deprecated
- What are the conditions for Mitsubishi PLC to realize Ethernet wireless communication?
- Implementation code of interceptor and filter
- 1.20 study univariate linear regression
猜你喜欢

Slider verification - personal test (JD)

Relationship extraction --r-bert

Drawing with MATLAB (1)

The solution of positioning failure caused by framework jump

Optimize quiver function in MATLAB to draw arrow diagram or vector diagram (1) -matlab development

Degree of freedom analysis_ nanyangjx

三菱PLC若想实现以太网无线通讯,需要具备哪些条件?

WBC learning notes (I): manually push WBC formula

Whale conference one-stop intelligent conference system helps organizers realize digital conference management

Bezier curve learning
随机推荐
Selenium 搭建 Cookies池 绕过验证反爬登录
Summary of common instructions for arm assembly
自动化测试中,三种常用的等待方式,强制式(sleep) 、 隐式 ( implicitly_wait ) 、显式(expected_conditions)
Digital image processing learning (II): Gaussian low pass filter
Is it safe to open an account in flush,
Performance comparison of unaryexpr's function on matrix elements in eigen Library
Exploration of webots and ROS joint simulation (I): software installation
Structure diagram of target detection network
VS2005 compiles libcurl to normaliz Solution of Lib missing
Polka lines code recurrence
WBC learning notes (II): practical application of WBC control
Reverse crawling verification code identification login (OCR character recognition)
ImportError: ERROR: recursion is detected during loading of “cv2“ binary extensions. Check OpenCV in
Recovering the system with Clonezilla USB disk
Install Anaconda + NVIDIA graphics card driver + pytorch under win10_ gpu
WBC learning notes (I): manually push WBC formula
Backward usage
How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?
Realizing sequence annotation with transformers
关于极客时间 | MySQL实战45讲的部分总结