pbootcms修改文章排序机制

 

在apps\admin\model\content\ContentModel.php文件里新增方法,以下方法是栏目单独排序 ,如果要所有的文章整体排序,在方法和sql语句里删除$scode的相关代码即可

// 获取栏目下最大排序值
public function getMaxSorting($scode)
{
    // PBootCMS 原生查询写法
    $sql = "SELECT MAX(sorting) AS max_sorting FROM ay_content WHERE scode = '$scode'";
    $row = Db::one($sql); // 注意:有些版本是 one() 而不是 getOne()

    return isset($row->max_sorting) ? (int)$row->max_sorting : 0;
}

//或者者使用下面的方法
// 获取栏目下最大排序值
public function getMaxSorting($scode)
{
    // 使用框架内置的 table 方法进行聚合查询
    $max_sorting = parent::table('ay_content')
        ->where("scode='$scode'")
        ->max('sorting');

    return $max_sorting ? (int)$max_sorting : 0;
}

ContentModel.php文件中替换 a.sorting ASC 为 a.sorting DESC

apps\admin\controller\content\ContentController.php 文件的add()方法里新增

// 获取当前栏目下最大排序值
$maxSorting = $this->model->getMaxSorting($scode);
// 如果栏目下还没有文章,给一个初始值
$sorting = $maxSorting ? $maxSorting + 10 : 10;

 

 

版权声明:
作者:鲤小牛
链接:https://yunweiba.com/211.html
来源:运维吧
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>