控制访问量和点赞量

在后台文章内容处增加可控制文章的访问量和点赞量功能

首先打开apps/admin/controller/content/ContentController.php 在里面查找

    // 文章修改
  public function mod()
  {
   if (! ! $submit = post('submit')) {
   switch ($submit) {

在下面添加代码

  case 'pbootnet': // 修改文章访问量
  $listall = post('listall');
  if ($listall) {
  $visits = post('visits');
  foreach ($listall as $key => $value) {
  if ($visits[$key] === '' || ! is_numeric($visits[$key]))
   $visits[$key] = visits;
  $this->model->modContent($value, "visits=" . $visits[$key]);
   }
$likes = post('likes');
 foreach ($listall as $key => $value) {
 if ($likes[$key] === '' || ! is_numeric($likes[$key]))
 $likes[$key] = likes;
 $this->model->modContent($value, "likes=" . $likes[$key]);
  }	
$this->log('修改内容访问量成功!');
  success('修改成功!', - 1);
} else {
alert_back('修改失败,无任何内容!');
  }
  break;

添加完毕保存后再打开/apps/admin/model/content/ContentModel.php,在每一个如下代码中添加'a.likes',

$field = array(

            'a.id',

            'b.name as sortname',

            'a.scode',

            'c.name as subsortname',

            'a.subscode',

            'a.title',

            'a.subtitle',

            'a.date',

            'a.sorting',

            'a.status',

            'a.istop',

            'a.isrecommend',

            'a.isheadline',

            'a.visits',

            'a.likes',

            'a.ico',

            'a.pics',

            'a.filename',

            'a.outlink',

            'd.urlname',

            'b.filename as sortfilename'

        );

添加完后打开/apps/admin/view/default/content/content.html  在

<th>访问量</th>

下添加

<th>点赞量</th>

然后查找

<td>value->visits</td>

将其替换为

<td class="table-input"><input type="text" lay-ignore class="layui-input" name="visits[]" value="[value->visits]"></td>
<td class="table-input"><input type="text" lay-ignore class="layui-input" name="likes[]" value="[value->likes]"></td>

继续查找 

<button type="submit" name="submit" value="sorting" class="layui-btn layui-btn-sm">保存排序</button>

在其后面添加 

<button type="submit" name="submit" value="pbootnet" class="layui-btn layui-btn-sm">保存阅读点赞量</button>
返回顶部