默认情况下,PHPCMS V9后台的推送指定文章到指定栏目 相当于 给指定栏目添加这些指定的外链文章(点击这些外链文章,跳转的页面地址还是原文章的地址),通常这样就能满足我们的“复制”文章需求。
有些朋友可能会发现,如果要复制的文章的模型有自定义字段,使用后台的推送到指定栏目功能,“复制”过去的文章在编辑的时候,自字义字段显示为空。其实这也是正常现象,因为上面咱们也说了,这样“复制”的文章,毕竟是外链,没必要要内容和一些自定义字段信息。
那如果想实现真正意义上的复制文章到指定栏目中呢?(”复制“的文章不是外链文章,内容和自定义字段都要可以复制过去),现在就说下方法:(注:此方法只适用于复制指定文章到同模型的指定栏目中,模型不同一般字段不同,字段都不同,想把自定义字段复制哪去?)
直接在原来推送文章到指定栏目的功能基础上修改:打开phpcms\modules\content\classes\push_api.class.php文件,查找 foreach($id_arr as $id) { 将下面的:
$r = $this->db->get_one(array('id'=>$id));
$linkurl = preg_match('/^http:\/\//',$r['url']) ? $r['url'] : siteurl($siteid).$r['url'];
foreach($ids as $catid) {
$siteid = $siteids[$catid];
$this->categorys = getcache('category_content_'.$siteid,'commons');
$modelid = $this->categorys[$catid]['modelid'];
$this->db->set_model($modelid);
$newid = $this->db->insert(
array('title'=>$r['title'],
'style'=>$r['style'],
'thumb'=>$r['thumb'],
'keywords'=>$r['keywords'],
'description'=>$r['description'],
'status'=>$r['status'],
'catid'=>$catid,
'url'=>$linkurl,
'sysadd'=>1,
'username'=>$r['username'],
'inputtime'=>$r['inputtime'],
'updatetime'=>$r['updatetime'],
'islink'=>1
),true);
$this->db->table_name = $this->db->table_name.'_data';
$this->db->insert(array('id'=>$newid));
$hitsid = 'c-'.$modelid.'-'.$newid;
$this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$catid,'updatetime'=>SYS_TIME));
}
替换为:
/* 大海哪蓝 1764360234@qq.com add at 20190612 start*/
$r1 = $this->db->get_one(array('id'=>$id));
$this->db->table_name = $this->db->table_name.'_data';
$r2 = $this->db->get_one(array('id'=>$id));
$r = array_merge($r1,$r2);
$r = array_map('htmlspecialchars_decode',$r);
foreach($ids as $catid) {
$siteid = $siteids[$catid];
$this->categorys = getcache('category_content_'.$siteid,'commons');
$modelid = $this->categorys[$catid]['modelid'];
$this->db->set_model($modelid);
$r['catid'] = $catid;
$this->db->add_content($r);
}
/* 大海哪蓝 1764360234@qq.com add at 20190612 end */