西安网站建设
在线咨询

扫描二维码分享到微信

phpcms多模型相关文章插件v1.0插件bug修复

【建站知识】  2021-09-25 

phpcms多模型相关文章插件v1.0

phpcms在后台添加文章的时候,可以选择相关文章。这本来是一个很好的功能,但是却只能选择相同模型的文章,不能跨模型选择文章。今天发布的这个插件就是解决这个问题的。

使用方法:

1:下载插件包  phpcms多模型相关文章插件.zip

2:解压后把relation文件夹复制到moudles文件夹下。

3:后台模块管理安装relation模块;

4:模块多模型相关文章安装,然后安装成功后会提示创建成功,您可以使用多模型相关文章功能

 

5 : 现在可以去添加一个文章,然后点击相关文章按钮进行测试,发现我们可以选择多个模型的栏目了。

 

6:选择相关文章保存后,访问这篇文章。可以看到下载模型的文章出现在新闻模型的文章中。

插件bug修复:

找到\phpcms\modules\content\classes\content_tag.class.php

并找到插件文件\phpcms\modules\relation\src\content_tag.class.php

要修改以上2个文件,具体教程看下面:

修复必须手动选择相关文章的bug。修复后,没有手动选择相关文章时,可以根据关键词自动相关文章:

\phpcms\modules\content\classes\content_tag.class.php

找到“相关文章标签”:

public function relation($data) {

         $catid = intval($data['catid']);

         $modelid = intval($data['modelid']);

         if(!$this->set_modelid($catid) && $modelid) {

              $this->db->set_model($modelid);

              $this->tablename = $this->db->table_name;

         } elseif(!$this->set_modelid($catid)) {

              return false;

         }

         $order = $data['order'];

         $sql = "`status`=99";

         $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

         if($data['relation']) {

              $relations = explode('|',trim($data['relation'],'|'));

              $relations = array_diff($relations, array(null));

              $relations = implode(',',$relations);

              $sql = " `id` IN ($relations)";

              $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

         } elseif($data['keywords']) {

              $keywords = str_replace(array('%',"'"), '',$data['keywords']);

              $keywords_arr = explode(' ',$keywords);

              $key_array = array();

              $number = 0;

              $i =1;

              $sql .= " AND catid='$catid'";

              foreach ($keywords_arr as $_k) {

                   $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                   $r = $this->db->select($sql2, '*', $limit, '','','id');

                   $number += count($r);

                   foreach ($r as $id=>$v) {

                       if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                       $i++;

                   }

                   if($data['limit']<$number) break;

              }

         }

         if($data['id']) unset($key_array[$data['id']]);

         return $key_array;

     }

 

修改为:

public function relation($data) {

         $catid = intval($data['catid']);

         $modelid = intval($data['modelid']);

         if(!$this->set_modelid($catid) && $modelid) {

              $this->db->set_model($modelid);

              $this->tablename = $this->db->table_name;

         } elseif(!$this->set_modelid($catid)) {

              return false;

         }

         $order = $data['order'];

         $sql = "`status`=99";

         $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

         if($data['relation']) {

              $relations = explode(',',$data['relation']);

              foreach ($relations as $key => $value) {

                   //类别id|模型id

                   $modelid_arr[] =  explode('|',$value);

              }

              foreach ($modelid_arr as $akey => $avalue) {

                   //模型id组成的数组

                   $modelid_narr[] =  $avalue[1];

                   //id组成的数组

                   $catidsarr[] = $avalue[0];

              }

              //去除重复的modelid

              $modelid_newarr = array_unique($modelid_narr);

              //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

              $data1= array();

              foreach ($modelid_newarr as $key1 => $value1) {             

                   $relation= array();

                   foreach ($modelid_arr as $key2 => $value2) {

 

                       if($value2[1] == $value1){

                            $relation[] = $value2[0];

                       }

 

                   }

                   if(sizeof($relation)>0){

                       $catids_str = implode(',', $relation);

                       $sql = " `id` IN ($catids_str)";

                   }else{

                       $sql="";

                   }

             

     

                   $this->db->set_model($value1);

                   $this->tablename = $this->db->table_name;

                   $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

                   $data1= array_merge($data1, $key_array);

             }

         }elseif($data['keywords']) {

 

              $keywords = str_replace(array('%',"'"), '',$data['keywords']);

              $keywords_arr = explode(' ',$keywords);

              $key_array = array();

              $number = 0;

              $i =1;

              $sql .= " AND catid='$catid'";

              foreach ($keywords_arr as $_k) {

                   $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                   $r = $this->db->select($sql2, '*', $limit, '','','id');

                   $number += count($r);

                   foreach ($r as $id=>$v) {

                       if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                       $i++;

                   }

                   if($data['limit']<$number) break;

              }

              $data1 = $key_array;

         }

         return $data1;

     }

    

 

 

第二种方法:

或者直接将插件里的\phpcms\modules\relation\src\content_tag.class.php

里的

public function relation($data) {

           $catid = intval($data['catid']);

           $modelid = intval($data['modelid']);

           if(!$this->set_modelid($catid) && $modelid) {

                 $this->db->set_model($modelid);

                 $this->tablename = $this->db->table_name;

           } elseif(!$this->set_modelid($catid)) {

                 return false;

           }

           $order = $data['order'];

           $sql = "`status`=99";

           $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

           if($data['relation']) {

                 $relations = explode(',',$data['relation']);

                

                 foreach ($relations as $key => $value) {

                      //类别id|模型id

                      $modelid_arr[] =  explode('|',$value);

                 }

                 foreach ($modelid_arr as $akey => $avalue) {

                      //模型id组成的数组

                      $modelid_narr[] =  $avalue[1];

                      //id组成的数组

                      $catidsarr[] = $avalue[0];

                 }

                

                 //去除重复的modelid

                 $modelid_newarr = array_unique($modelid_narr);

 

                

                 //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

                 $data1= array();

 

                 foreach ($modelid_newarr as $key1 => $value1) {               

                 $relation= array();

                 foreach ($modelid_arr as $key2 => $value2) {

 

                      if($value2[1] == $value1){

                            $relation[] = $value2[0];

                      }

 

                 }

 

 

                 if(sizeof($relation)>0){

                     $catids_str = implode(',', $relation);

 

                      $sql = " `id` IN ($catids_str)";

                 }else{

                      $sql="";

                 }

                

     

                 $this->db->set_model($value1);

                 $this->tablename = $this->db->table_name;

                

 

                      $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

             

               

                       $data1= array_merge($data1, $key_array);

                     

                     

               }

 

             

                

          

           }

          

           return $data1;

      }

 

修改为:

public function relation($data) {

           $catid = intval($data['catid']);

           $modelid = intval($data['modelid']);

           if(!$this->set_modelid($catid) && $modelid) {

                 $this->db->set_model($modelid);

                 $this->tablename = $this->db->table_name;

           } elseif(!$this->set_modelid($catid)) {

                 return false;

           }

           $order = $data['order'];

           $sql = "`status`=99";

           $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

           if($data['relation']) {

                 $relations = explode(',',$data['relation']);

                 foreach ($relations as $key => $value) {

                      //类别id|模型id

                      $modelid_arr[] =  explode('|',$value);

                 }

                 foreach ($modelid_arr as $akey => $avalue) {

                      //模型id组成的数组

                      $modelid_narr[] =  $avalue[1];

                      //id组成的数组

                      $catidsarr[] = $avalue[0];

                 }

                 //去除重复的modelid

                 $modelid_newarr = array_unique($modelid_narr);

                 //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

                 $data1= array();

                 foreach ($modelid_newarr as $key1 => $value1) {               

                      $relation= array();

                      foreach ($modelid_arr as $key2 => $value2) {

 

                            if($value2[1] == $value1){

                                  $relation[] = $value2[0];

                            }

 

                      }

                      if(sizeof($relation)>0){

                            $catids_str = implode(',', $relation);

                            $sql = " `id` IN ($catids_str)";

                      }else{

                            $sql="";

                      }

                

     

                      $this->db->set_model($value1);

                      $this->tablename = $this->db->table_name;

                      $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

                      $data1= array_merge($data1, $key_array);

               }

           }elseif($data['keywords']) {

 

                 $keywords = str_replace(array('%',"'"), '',$data['keywords']);

                 $keywords_arr = explode(' ',$keywords);

                 $key_array = array();

                 $number = 0;

                 $i =1;

                 $sql .= " AND catid='$catid'";

                 foreach ($keywords_arr as $_k) {

                      $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                      $r = $this->db->select($sql2, '*', $limit, '','','id');

                      $number += count($r);

                      foreach ($r as $id=>$v) {

                            if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                            $i++;

                      }

                      if($data['limit']<$number) break;

                 }

                 $data1 = $key_array;

           }

           return $data1;

      }

     


上一篇:phpcms v9禁止提交信息到官网方法详解-解决phpcms后台慢的问题-最佳解决方法
下一篇:phpcms正则替换-替换br-替换img-替换<---正则替换分页pages-手机端分页 正则替换增加m目录分页

网站栏目

建站知识 前端设计 酷站欣赏 SEO优化 网络营销 服务器安全 行业新闻 公司新闻 建站工具 博客


最新文章

玩转知道创宇:宝塔面板Nginx防火墙如何添加知道创宇云加速节点ip白名单

玩转知道创宇:宝塔面板Nginx防

知道创宇云加速是非常好的网站免费加速服务,只要网站备案了就可以免费试用。但是很多...

玩转知道创宇:宝塔面板Nginx防

知道创宇云加速是非常好的网站免费加速服务,只要网站备案了就可以免费试用。但是很多...


相关内容

PHPCMS同步发布到其他栏目遇到

当选择同步发布到其他栏目的时候,内容有转向链接,会造成出错(提示Table &lsquo;xxx...

phpcms调用随机栏目 随机调用S

phpcms调用随机栏目 随机调用SQL语句,可以使用PHPCMS的get标签,指定模型下随机栏目...

phpcms报错Notice: Constant

Notice: Constant CACHE_PATH already defined inD: WEB WWW AA-phpcms...

phpcmsv9的关联链接加seo-title

phpcmsv9的关联链接加seo-title1、通过修改源文件实现。打开phpcms modules content...

PHPCMS V9 关联链接增加批量

PHPCMS V9关联链接的作用不再阐述,具体功能位置为后台-扩展-关联链接;本身不具备批...

phpcms文章页调用缩略图-文章页

phpcms文章页调用缩略图-文章页怎么调缩略图使用标签:{$rs[thumb]}

PHPCMS自定义文章内容页别名

PHPCMS自定义文章内容页别名 生成纯静态{$url}无法获取当前文章网址-自定义url无法获...

phpcms标签无法调用出来$r['id'

phpcms标签无法调用出来$r[ id ] $r2[ id ] $rs[ id ]  $data[ id ]---id失效-url失效-内容url失效

phpcms多模型相关文章插件v1.0插件bug修复


随机推荐

sql语句查询根据关键词 查询相

sql语句查询根据关键词 查询相关标题的内容SELECT*FROMdede_archivesWHEREtitleLIKE& 39;%风格要素%& 39;

phpcms continue-if循环判断

phpcms continue-if循环判断可用的方法:<?phpif($v[catid]==235||$v[catid]==236){co...

jquery加速和css加速:使用第三

jquery加速和css加速:使用第三方CDN加速服务加载js css bootstrap

RGCMS建站管理系统更新日志2021

版本号:2021012601更新内容:修复about标签中参数id或nid失效的问题;修复栏目列表中...

宝塔什么环境下放置PbootCMS可

宝塔什么环境下放置PbootCMS可以达到最好的兼容

phpcms v9建网站 php格式化

用PHPCMS V9 建站时,经常会用到时间标签,它是通用标签调用-日期时间格式化,适用全...


  微信小程序开发   西安网站优化   西安建站公司   西安SEO   西安网站SEO优化   西安SEO优化   西安小程序开发

Copyright ©2018-2021 黑米网络 | 网站建设 | XML地图 | 文章 | 地图 | 标签 | www.xaheimi.com | 最新更新: 2021-09-25 15:38:19