腾讯云服务器优惠活动华纳云香港服务器

Typecho站点MIP页面如何添加百度统计和百度联盟广告?

首先无论是百度统计还是百度广告在 MIP 里都是以组件形式出现的,所以要添加只能是在 MIP 改造 PHP 文件里来实现,因为本博客一直以来都是使用[AMP/MIP for Typecho]插件(可参考【推荐一款集成 AMP、MIP、熊掌号的 Typecho 插件】一文)来完成改造的,所以添加 MIP 组件也就是在 AMP/MIP for Typecho 插件基础上来添加了。

添加百度统计组件

首先打开 plugins/AMP/templates/MIPpage.php 找到如下代码:

  1. <div class=“footer”><p>© 2018 <a data-type=“mip” href=“https://github.com/holmesian/Typecho-AMP”>MIP for     Typecho</a> v<?php print($this->version); ?> , Designed by  <a href=“https://holmesian.org/” target=“_blank”>Holmesian</a>.</p></div>
  2. <mip-fixed type=“gototop”>
  3. <mip-gototop></mip-gototop>
  4. </mip-fixed>

在这段代码之前、之后都可以,放如下代码:

  1. <script src=“https://c.mipcdn.com/static/v1/mip-stats-baidu/mip-stats-baidu.js”></script>
  2. <mip-stats-baidu>
  3.     <script type=“application/json”>
  4.         {
  5.             “token”“这里放你百度统计代码 hm 后面的 token 串哦!”,
  6.             “_setCustomVar”: [1, “login”“1”, 2],
  7.             “_setAutoPageview”: [true]
  8.         }
  9.     </script>
  10. </mip-stats-baidu>

然后保存,在 AMP/MIP for Typecho 后台清除一下缓存后即可。

添加百度联盟广告组件

同样打开 plugins/AMP/templates/MIPpage.php 文件,找到如下代码:

  1. <div class=“tip”>当前页面是本站的「<a href=“https://www.mipengine.org/”>Baidu MIP</a>」> 版。发表评论请点击:<a href=“<?php print($MIPpage[‘permalink’]); ?>”>完整版 »</a></div>
  2. <?php if(!$MIPpage[‘isMarkdown’]){print(‘<div class=“tip-error”>因本文不是用 Markdown 格式
  3.     的编辑器书写的,转换的页面可能不符合 MIP 标准。</div>’);} ?>
  4. </article>
  5. </div>

在上面代码的前面添加如下代码:

  1. <script src=“https://c.mipcdn.com/static/v1/mip-ad/mip-ad.js”></script>
  2. <div class=“mip-adbd”>
  3. <mip-ad type=“ad-baidu” cproid=“uXXXXXX”>
  4. </mip-ad>
  5. </div>

其中的 cproid 赋值 uXXXXXX 替换为你要在 MIP 页面显示的百度联盟广告代码里的编号即可。

以上内容整理自@明月登楼学习笔记 Blog

本文地址:https://boke112.com/post/5654.html

赞 (0) 打赏
版权声明:本文为原创文章,版权归 boke112百科 所有,欢迎分享本文,转载请保留出处!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
wu