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

 

默认情况下,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 */

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大海哪蓝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值