PHPCMS V9后台复制指定文章到同模型的指定栏目中

 4210

默认情况下,PHPCMS V9后台的推送指定文章到指定栏目 相当于 给指定栏目添加这些指定的外链文章(点击这些外链文章,跳转的页面地址还是原文章的地址),通常这样就能满足我们的“复制”文章需求。

有些朋友可能会发现,如果要复制的文章的模型有自定义字段,使用后台的推送到指定栏目功能,“复制”过去的文章在编辑的时候,自字义字段显示为空。其实这也是正常现象,因为上面咱们也说了,这样“复制”的文章,毕竟是外链,没必要要内容和一些自定义字段信息。

那如果想实现真正意义上的复制文章到指定栏目中呢?(”复制“的文章不是外链文章,内容和自定义字段都要可以复制过去),现在就说下方法:(注:此方法只适用于复制指定文章到同模型的指定栏目中,模型不同一般字段不同,字段都不同,想把自定义字段复制哪去?)

直接在原来推送文章到指定栏目的功能基础上修改:打开 phpcms\modules\content\classes\push_api.class.php 文件,查找  foreach($id_arr as $id) { 将下面的:

  1. $r = $this->db->get_one(array('id'=>$id));
  2. $linkurl = preg_match('/^http:\/\//',$r['url']) ? $r['url'] : siteurl($siteid).$r['url'];
  3. foreach($ids as $catid) {
  4.     $siteid = $siteids[$catid];
  5.     $this->categorys = getcache('category_content_'.$siteid,'commons');
  6.     $modelid = $this->categorys[$catid]['modelid'];
  7.     $this->db->set_model($modelid);
  8.         $newid = $this->db->insert(
  9.         array('title'=>$r['title'],
  10.             'style'=>$r['style'],
  11.             'thumb'=>$r['thumb'],
  12.             'keywords'=>$r['keywords'],
  13.             'description'=>$r['description'],
  14.             'status'=>$r['status'],
  15.             'catid'=>$catid,
  16.             'url'=>$linkurl,
  17.             'sysadd'=>1,
  18.             'username'=>$r['username'],
  19.             'inputtime'=>$r['inputtime'],
  20.             'updatetime'=>$r['updatetime'],
  21.             'islink'=>1
  22.         ),true);
  23.         $this->db->table_name = $this->db->table_name.'_data';
  24.         $this->db->insert(array('id'=>$newid));
  25.         $hitsid = 'c-'.$modelid.'-'.$newid;
  26.         $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$catid,'updatetime'=>SYS_TIME));
  27. }

替换为:

  1. $r1 = $this->db->get_one(array('id'=>$id));
  2. $this->db->table_name = $this->db->table_name.'_data';
  3. $r2 = $this->db->get_one(array('id'=>$id));
  4. $r = array_merge($r1,$r2);
  5. $r = array_map('htmlspecialchars_decode',$r);
  6. foreach($ids as $catid) {
  7.     $siteid = $siteids[$catid];
  8.     $this->categorys = getcache('category_content_'.$siteid,'commons');
  9.     $modelid = $this->categorys[$catid]['modelid'];
  10.     $this->db->set_model($modelid);
  11.     $r['catid'] = $catid;
  12.     $this->db->add_content($r);
  13. }


本文网址:https://www.zztuku.com/detail-7758.html
站长图库 - PHPCMS V9后台复制指定文章到同模型的指定栏目中
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐