织梦发布文章实现百度主动推送熊掌推送与批量推送的方法

时间:2021-11-25
类别:教程 - CMS教程

百度主动推送(实时)可以缩短百度爬虫发现您站点新链接的时间,使新发布的页面可以在第一时间被百度收录,织梦程序我们可以在后台添加文档完成那一刻即时主动推送到百度或熊掌,也可以在后台文档列表里批量推送。

环境要求:PHP必须开启了curl扩展。

一、织梦百度主动推送教程:

1、织梦网站后台-系统-基本参数,添加新变量,如果变量值未填写或者为空将不推送:

变量名称:cfg_baidu_push

参数说明:百度推送接口

变量值:登录你的百度平台 https://ziyuan.baidu.com 获取接口调用地址

获取接口调用地址

2、打开 /dede(后台目录)/inc/inc_archives_functions.php 在文件最末尾插入

  1. /** 
  2.  
  3.  * 百度主动推送 
  4.  
  5.  */ 
  6.  
  7. function baidu_push($id="",$qstr=""
  8.  
  9.  
  10.     global $cfg_multi_site,$cfg_basehost,$cfg_baidu_push
  11.  
  12.     if(!emptyempty($id) && !emptyempty($cfg_baidu_push)) 
  13.  
  14.     { 
  15.  
  16.         if( !emptyempty($id) && emptyempty($qstr) ) $qstr = $id
  17.  
  18.         if($qstr==''
  19.  
  20.         { 
  21.  
  22.             exit(); 
  23.  
  24.         } 
  25.  
  26.         $qstrs = explode('`',$qstr); 
  27.  
  28.         $cfg_domain = $cfg_multi_site == 'N' ? $cfg_basehost : ''
  29.  
  30.         $urls = array(); 
  31.  
  32.         $i = 0; 
  33.  
  34.         foreach($qstrs as $aid
  35.  
  36.         { 
  37.  
  38.             $i++; 
  39.  
  40.             $arcrow = GetOneArchive($aid); 
  41.  
  42.             $url = $cfg_domain.$arcrow['arcurl']; 
  43.  
  44.             $urls[] = $url
  45.  
  46.             $artlist .= $url."<br />"
  47.  
  48.         } 
  49.  
  50.         if($i>1) $artlist = ""
  51.  
  52.         if(!emptyempty($urls)){ 
  53.  
  54.             $ch = curl_init(); 
  55.  
  56.             $options =  array
  57.  
  58.                 CURLOPT_URL => trim($cfg_baidu_push), 
  59.  
  60.                 CURLOPT_POST => true, 
  61.  
  62.                 CURLOPT_RETURNTRANSFER => true, 
  63.  
  64.                 CURLOPT_POSTFIELDS => implode(" "$urls), 
  65.  
  66.                 CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), 
  67.  
  68.             ); 
  69.  
  70.             curl_setopt_array($ch$options); 
  71.  
  72.             $result = curl_exec($ch); 
  73.  
  74.             curl_close($ch); 
  75.  
  76.             $result = json_decode($result, true); 
  77.  
  78.             if(isset($result['success'])){ 
  79.  
  80.                 $not_same_site = isset($result['not_same_site'][0]) ? " <font style='color:#f00;'>推送链接与百度绑定站点不一致</font> " : ""
  81.  
  82.                 $not_valid = isset($result['not_valid'][0]) ? " <font style='color:#f00;'>推送链接不合法</font> " : ""
  83.  
  84.                 return $not_same_site . $not_valid . '百度主动推送成功 '.$result['success'].' 条!当天剩余 '.$result['remain'].' 条可推送!'.$artlist
  85.  
  86.             }else
  87.  
  88.                 return '百度主动推送失败,错误码:'.$result['error'].'<a href=https://ziyuan.baidu.com/college/courseinfo?id=267&page=2#h2_article_title12 target=_blank>详情</a>'
  89.  
  90.             } 
  91.  
  92.         } 
  93.  
  94.         return "没有数据被推送!"
  95.  
  96.     } 
  97.  

3、找到后台文档发布程序PHP文件

【普通文章】模型的是:/dede/article_add.php

【图片集】模型的是:/dede/album_add.php

【软件】模型的是:/dede/soft_add.php

【商品/自定义模型】模型的是:/dede/archives_add.php

根据你的需要在对应的php文件中找到

  1. //返回成功信息 

在它上面加入

  1. if(!emptyempty($cfg_baidu_push)) 
  2.  
  3.  
  4.     $backurl .= "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".baidu_push($arcID)."</p>"
  5.  

继续找到

  1. line-height:36px;height:36px 

改成

  1. line-height:36px; 

至此,织梦发布文档主动推送到百度功能完成。

二、熊掌主动推送(实时)实现方法:

1、织梦网站后台-系统-基本参数,添加新变量,如果变量值未填写或者为空将不推送

变量名称:cfg_xiong_push

参数说明:熊掌推送接口

变量值:登录你的百度平台 https://ziyuan.baidu.com/ydzq/ 获取接口调用地址

如图,天级收录和周级收录都可以:

熊掌推送天级收录

周级收录

注意你的站点域名已绑定上熊掌id。

获取接口调用地址

2、打开 /dede(后台目录)/inc/inc_archives_functions.php 在文件最末尾插入

  1. /** 
  2.  
  3.  * 熊掌主动推送 
  4.  
  5.  */ 
  6.  
  7. function xiong_push($id="",$qstr=""
  8.  
  9.  
  10.     global $cfg_multi_site,$cfg_basehost,$cfg_xiong_push
  11.  
  12.     if(!emptyempty($id) && !emptyempty($cfg_xiong_push)) 
  13.  
  14.     { 
  15.  
  16.         if( !emptyempty($id) && emptyempty($qstr) ) $qstr = $id
  17.  
  18.         if($qstr==''
  19.  
  20.         { 
  21.  
  22.             exit(); 
  23.  
  24.         } 
  25.  
  26.         $qstrs = explode('`',$qstr); 
  27.  
  28.         $cfg_domain = $cfg_multi_site == 'N' ? $cfg_basehost : ''
  29.  
  30.         $urls = array(); 
  31.  
  32.         $i = 0; 
  33.  
  34.         foreach($qstrs as $aid
  35.  
  36.         { 
  37.  
  38.             $i++; 
  39.  
  40.             $arcrow = GetOneArchive($aid); 
  41.  
  42.             $url = $cfg_domain.$arcrow['arcurl']; 
  43.  
  44.             $urls[] = $url
  45.  
  46.             $artlist .= $url."<br />"
  47.  
  48.         } 
  49.  
  50.         if($i>1) $artlist = ""
  51.  
  52.         if(!emptyempty($urls)){ 
  53.  
  54.             $ch = curl_init(); 
  55.  
  56.             $options =  array
  57.  
  58.                 CURLOPT_URL => trim($cfg_xiong_push), 
  59.  
  60.                 CURLOPT_POST => true, 
  61.  
  62.                 CURLOPT_RETURNTRANSFER => true, 
  63.  
  64.                 CURLOPT_POSTFIELDS => implode(" "$urls), 
  65.  
  66.                 CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), 
  67.  
  68.             ); 
  69.  
  70.             curl_setopt_array($ch$options); 
  71.  
  72.             $result = curl_exec($ch); 
  73.  
  74.             curl_close($ch); 
  75.  
  76.             $result = json_decode($result, true); 
  77.  
  78.             if(isset($result['error'])){ 
  79.  
  80.                 return '熊掌主动推送失败,错误码:'.$result['error'].' message:'.$result['message']; 
  81.  
  82.             }else
  83.  
  84.                 $not_same_site = isset($result['not_same_site'][0]) ? " <font style='color:#f00;'>推送链接与熊掌绑定站点不一致</font> " : ""
  85.  
  86.                 $not_valid = isset($result['not_valid'][0]) ? " <font style='color:#f00;'>推送链接不合法</font> " : ""
  87.  
  88.                 return $not_same_site . $not_valid . '熊掌主动推送成功 '.$result['success_batch'].$result['success_realtime'].' 条!当天剩余 '.$result['remain_batch'].$result['remain_realtime'].' 条可推送!'.$artlist
  89.  
  90.             } 
  91.  
  92.         } 
  93.  
  94.         return "没有数据被推送!"
  95.  
  96.     } 
  97.  

3、找到后台文档发布程序PHP文件

【普通文章】模型的是:/dede/article_add.php

【图片集】模型的是:/dede/album_add.php

【软件】模型的是:/dede/soft_add.php

【商品/自定义模型】模型的是:/dede/archives_add.php

根据你的需要在对应的php文件中找到

  1. //返回成功信息 

在它上面加入

  1. if(!emptyempty($cfg_xiong_push)) 
  2.  
  3.  
  4.     $backurl .= "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".xiong_push($arcID)."</p>"
  5.  

继续找到,如果你前面已经删除过height:36px,可以跳过这一步

  1. line-height:36px;height:36px 

改成

  1. line-height:36px; 

至此,织梦发布文档主动推送到熊掌功能完成。

三、织梦后台文档列表添加批量推送至百度/推送至熊掌,批量推送实现教程:

在加入批量之前必须完成上面的【织梦百度主动推送教程】第1、第2步 和 【织梦熊掌主动推送教程】第1、第2步,否则以下教程无效

1、打开 /dede/templets/content_list.htm (软件模型和自定义模型是 /dede/templets/content_i_list.htm) 找到

  1. 删除属性 

这一行,在它下面添加

  1. <a href="javascript:baidu_push(0)" class="coolbg">&nbsp;推送至百度&nbsp;</a> 
  2.  
  3. <a href="javascript:xiong_push(0)" class="coolbg">&nbsp;推送至熊掌&nbsp;</a> 
  4.  
  5. <script type="text/javascript"
  6.  
  7. function baidu_push(aid) 
  8.  
  9.  
  10.     var qstr=getCheckboxItem(); 
  11.  
  12.     if(aid==0) aid = getOneItem(); 
  13.  
  14.     location="archives_do.php?aid="+aid+"&dopost=baidu_push&qstr="+qstr; 
  15.  
  16.  
  17. function xiong_push(aid) 
  18.  
  19.  
  20.     var qstr=getCheckboxItem(); 
  21.  
  22.     if(aid==0) aid = getOneItem(); 
  23.  
  24.     location="archives_do.php?aid="+aid+"&dopost=xiong_push&qstr="+qstr; 
  25.  
  26.  
  27. </script> 

2、打开 /dede/archives_do.php 找到末尾一行的

  1. ?> 

在它上面加入

  1. else if($dopost=='baidu_push'
  2.  
  3.  
  4.     if( !emptyempty($aid) && emptyempty($qstr) ) $qstr = $aid
  5.  
  6.      
  7.  
  8.     if($qstr==''
  9.  
  10.     { 
  11.  
  12.         ShowMsg('参数无效!',$ENV_GOBACK_URL); 
  13.  
  14.         exit(); 
  15.  
  16.     } 
  17.  
  18.     require_once(DEDEADMIN.'/inc/inc_archives_functions.php'); 
  19.  
  20.     $result = baidu_push($qstr); 
  21.  
  22.     ShowMsg($result,$ENV_GOBACK_URL,0,5000); 
  23.  
  24.     exit(); 
  25.  
  26.  
  27. else if($dopost=='xiong_push'
  28.  
  29.  
  30.     if( !emptyempty($aid) && emptyempty($qstr) ) $qstr = $aid
  31.  
  32.      
  33.  
  34.     if($qstr==''
  35.  
  36.     { 
  37.  
  38.         ShowMsg('参数无效!',$ENV_GOBACK_URL); 
  39.  
  40.         exit(); 
  41.  
  42.     } 
  43.  
  44.     require_once(DEDEADMIN.'/inc/inc_archives_functions.php'); 
  45.  
  46.     $result = xiong_push($qstr); 
  47.  
  48.     ShowMsg($result,$ENV_GOBACK_URL,0,5000); 
  49.  
  50.     exit(); 
  51.  

到这里,批量推送教程已经完成。

    收藏