PbootCMS通过文章ID关联任意内容

453 阅读 1 评论 483 字

PbootCMS内容关联,可任意关联模型下的内容。因客户的需求这次二开了 {pboot:list} 内容列表调用标签,经过调整实现内容关联,你可以想怎么关联就怎么关联,如果想还是关联栏目下的全部,直接把所有ID输入进去,如果想单独关联栏目下的某及几个,也直接输入ID号,并可以通过ID号先后进行排序。

第一步: 在后台 全局配置 -> 模型字段 -> 扩展字段新增 添加一个用来输入多个ID的单行文本字段。

PbootCMS通过文章ID关联任意内容

PbootCMS通过文章ID关联任意内容

第二步:{pboot:list proid=''} 新增 proid 属性用来调用本产品所关联指定相关产品,相关代码如下:

scode=5 数字 5 代表的是所以调用关联产品所在的栏目ID,如果有多个可以用英文的逗号分割, {pboot:if('{content:ext_pro}'!='')}{/pboot:if} 判断没填写关联ID时不展示。

第三步: 修改文件 apps -> home -> controller -> ParserController.php 中的 parserListLabel 解析内容列表标签函数。在 1146 行定义 $proid = '' ; // ID关联

PbootCMS通过文章ID关联任意内容

在 1229 行加入代码如下:

    case 'proid':
    $proid = $value;

PbootCMS通过文章ID关联任意内容

在 1322 行, // 判断多图调节参数 位置之上加入代码如下:

// proid ID关联
$where4 = array();
if ($proid) {
    $proid_arr = explode(',', $proid);
    foreach ($proid_arr as $value) {
        if ($value) {
            $where4[] = "a.id='" . $value . "'";
        }
    }
}

PbootCMS通过文章ID关联任意内容

在 1392 行和 1395 行修改成如下代码:

if ($page) {
    if (isset($paging)) {
        error('请不要在一个页面使用多个具有分页的列表,您可将多余的使用page=0关闭分页!');
    } else {
        $paging = true;
        $data = $this->model->getLists($scode, $num, $order, $where1, $where2, $where3, $where4, $fuzzy, $start, $lfield);
    }
} else {
    $data = $this->model->getList($scode, $num, $order, $where1, $where2, $where3, $where4, $fuzzy, $start, $lfield);
}

PbootCMS通过文章ID关联任意内容

第四步: 修改两个函数 getLists() 和 getList(),修改文件 apps -> home -> model -> ParserModel.php ,大概在 260 行和 375 行,修改如下:

getLists 函数修改
// 未修改
public function getLists($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)

// 已修改
public function getLists($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $proid = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)


getList 函数修改
// 未修改
public function getList($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)

// 已修改
public function getList($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $proid = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)

在 365 行和 480 行处分别加入 ->where($proid, 'OR') 代码如下:

// 筛选条件支持模糊匹配
return parent::table('ay_content a')->field($fields)
      ->where($scode_arr, 'OR')
      ->where($where)
      ->where($select, 'AND', 'AND', $fuzzy)
      ->where($filter, 'OR')
      ->where($proid, 'OR') //关联内容条件查询
      ->where($tags, 'OR')
      ->join($join)
      ->order($order)
      ->page(1, $num, $start)
      ->decode()
      ->select();


// 筛选条件支持模糊匹配
return parent::table('ay_content a')->field($fields)
      ->where($scode_arr, 'OR')
      ->where($where)
      ->where($select, 'AND', 'AND', $fuzzy)
      ->where($filter, 'OR')
      ->where($proid, 'OR') //关联内容条件查询
      ->where($tags, 'OR')
      ->join($join)
      ->order($order)
      ->limit($start - 1, $num)
      ->decode()
      ->select();

完成

文章评论 (1)
  1. 轩 回复TA
    如何关联内容列表
QQ咨询
QQ号码
979779692
微信咨询
微信二维码
在线咨询
微信咨询 QQ咨询
客服头像

截屏,微信识别二维码

微信号:itx2021

(点击微信号复制,添加好友)

微信号已复制,请打开微信添加好友!