Typecho百度SEO插件(浏览页面自动提交给百度)

你是否在寻找一种有效的方法来提升博客文章在百度的曝光率?想知道如何在发布文章时即时推送并在用户浏览时自动提交链接?那么,Typecho百度SEO插件或许正是你所需要的解决方案!它不仅简化了推送流程,还有助于提升搜索引擎的收录效率。点击继续阅读,了解它的具体功能和使用方法吧!
摘要由智能技术生成

推荐一个很不错的插件:Typecho百度SEO插件

主要作用于发布文章的时候,会实时推送,而且在用户前端浏览的时候,也会进行百度推送,个人觉得更适合普通推送合适一点

本插件目前有两个功能:

1、发布文章时通过API主动将文章推送给百度

2、用户在前台浏览文章时,会在每个页面底部加载自动提交代码,将当前浏览的页面提交给百度

下载地址:

https://github.com/bluejay21st/Typecho-BaiduSeo
https://github.com/bluejay21st/Typecho-Sitemap

实现思路:

将功能的具体实现注册到对应的调用点。

启用插件后提示用户,要求设置提交接口。

发布文章后获取文章的链接与提交接口,提交数据,若提交失败给出提示。

前台访问触发后,将自动提交的JS代码输出到前台模板。

  1. 代码如下
  2. * @package BaiduSeo
  3. * @author 寒冬日志
  4. * @version 1.0.0
  5. * @link https://www.cwlog.net/
  6. */
  7. class BaiduSeo_Plugin implements Typecho_Plugin_Interface
  8. {
  9. /**
  10. * 激活插件方法,如果激活失败,直接抛出异常
  11. *
  12. * @access public
  13. * @return void
  14. * @throws Typecho_Plugin_Exception
  15. */
  16. public static function activate()
  17. {
  18. Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array('BaiduSeo_Plugin', 'publish_push');
  19. Typecho_Plugin::factory('Widget_Archive')->footer = array('BaiduSeo_Plugin', 'auto_push');
  20. return _t('请设置接口调用地址');
  21. }
  22. /**
  23. * 禁用插件方法,如果禁用失败,直接抛出异常
  24. *
  25. * @static
  26. * @access public
  27. * @return void
  28. * @throws Typecho_Plugin_Exception
  29. */
  30. public static function deactivate()
  31. {}
  32. /**
  33. * 获取插件配置面板
  34. *
  35. * @access public
  36. * @param Typecho_Widget_Helper_Form $form 配置面板
  37. * @return void
  38. */
  39. public static function config(Typecho_Widget_Helper_Form $form)
  40. {
  41. $api = new Typecho_Widget_Helper_Form_Element_Text('api', NULL, 'NULL', _t('接口调用地址'), _t('站长工具-普通收录-资源提交-API提交-接口调用地址<br>(格式如下:http://data.zz.baidu.com/urls?site=https://www.cwlog.net&token=xxxxxxxxxxx)'));
  42. $form->addInput($api->addRule('required', _t('请填写接口调用地址')));
  43. }
  44. /**
  45. * 个人用户的配置面板
  46. *
  47. * @access public
  48. * @param Typecho_Widget_Helper_Form $form
  49. * @return void
  50. */
  51. public static function personalConfig(Typecho_Widget_Helper_Form $form)
  52. {}
  53. /**
  54. * 发布文章时使用接口推送
  55. *
  56. * @access public
  57. * @return void
  58. */
  59. public static function publish_push($content, $edit)
  60. {
  61. $api = Typecho_Widget::widget('Widget_Options')->plugin('BaiduSeo')->api;
  62. if($api === 'NULL' || strpos($api, 'data.zz.baidu.com') !== 7) exit('<script>alert("请为BaiduSeo插件配置正确的接口调用地址");location.href="'.$siteUrl.'/admin/manage-posts.php";</script>');
  63. $db = Typecho_Db::get();
  64. $siteUrl = Typecho_Widget::widget('Widget_Options')->index;
  65. $content['cid'] = $edit->cid;
  66. $content['slug'] = $edit->slug;
  67. //获取分类缩略名
  68. $content['category'] = urlencode(current(Typecho_Common::arrayFlatten($db->fetchAll($db->select()->from('table.metas')
  69. ->join('table.relationships', 'table.relationships.mid = table.metas.mid')
  70. ->where('table.relationships.cid = ?', $content['cid'])
  71. ->where('table.metas.type = ?', 'category')
  72. ->order('table.metas.order', Typecho_Db::SORT_ASC)), 'slug')));
  73. //获取并格式化文章创建时间
  74. $content['created'] = $edit->created;
  75. $created = new Typecho_Date($content['created']);
  76. $content['year'] = $created->year; $content['month'] = $created->month; $content['day'] = $created->day;
  77. //生成URL
  78. $url = Typecho_Common::url(Typecho_Router::url($content['type'], $content), $siteUrl);
  79. //发送请求
  80. $urls = array(0=>$url);
  81. $ch = curl_init();
  82. $options = array(
  83. CURLOPT_URL => $api,
  84. CURLOPT_POST => true,
  85. CURLOPT_RETURNTRANSFER => true,
  86. CURLOPT_POSTFIELDS => implode("\n", $urls),
  87. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  88. );
  89. curl_setopt_array($ch, $options);
  90. $result = curl_exec($ch);
  91. $res = json_decode($result, true);
  92. if(isset($res['error'])) exit('<script>alert("链接提交百度接口失败!错误代码:'.$res['error'].',错误信息:'.$res['message'].'。");location.href="'.$siteUrl.'/admin/manage-posts.php";</script>');
  93. }
  94. /**
  95. * 用户浏览文章时自动推送
  96. *
  97. * @access public
  98. * @return void
  99. */
  100. public static function auto_push()
  101. {
  102. echo PHP_EOL.'<script>
  103. (function(){
  104. var bp = document.createElement("script");
  105. var curProtocol = window.location.protocol.split(":")[0];
  106. if (curProtocol === "https"){
  107. bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
  108. }else{
  109. bp.src = "http://push.zhanzhang.baidu.com/push.js";
  110. }
  111. var s = document.getElementsByTagName("script")[0];
  112. s.parentNode.insertBefore(bp, s);
  113. })();
  114. </script>'.PHP_EOL;
  115. }
  116. }

本站也有另外一款百度推送的插件

Typecho百度推送插件,普通or快速收录2种推送方式

就是一款针对百度站长(原熊掌号收录)推送,当发布文章的时候,可以同时推送给百度,实现快速收录的插件 目前,百度站长区分有普通和快速收录的接口,其中快速收录是根据网站....

区别:区分了快速推送和普通推送的功能,会获取数据保存到数据库方便查询

本次文章推荐的插件,部分功能已经整合到了spimes里面,自媒体比较更适合普通推送嘛……

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/881
2 条评论
8k

发表评论

已有 2 条评论

  1. bluejay21st     Win 10 /    Chrome
    2025-01-30 23:34

    我是作者,很意外我的插件会被转载,非常感谢。因为平时比较忙,改了博客的域名但是并没有及时做重定向以及更新插件,十分抱歉。
    大家如果需要可以去Github下载我的插件:
    https://github.com/bluejay21st/Typecho-BaiduSeo
    https://github.com/bluejay21st/Typecho-Sitemap

  2. 學哥     Android /    Chrome
    2022-04-26 20:54

    没有下载链接呀

!