美化 Z-Blog 友情链接 调用Favicon图标

yibin 2016-06-01 Z-Blog 672

前面介绍了《Typecho 友情链接获取Favicon图标》,在教程里面博客吧也说过JS这玩意现在基本是通用的,所以在Typecho可以使用JS实现的东西,在Z-Blog博客也是可以实现,只是由于Z-Blog的主题模板构造有点点不同,要给多个模板添加代码,考虑到新手可能会有点困难,所以博客吧在此特别介绍下。

Z-Blog 博客友情链接调用Favicon图标的方法

  1. 由于Z-Blog 博客的顶部并没有像WordPress或Typecho一样,用header.php文件实现,而是与index、sidebar、footer连在一起,所以要在default.html、single.htm、catalog.html、tags.html、gestbook.html、search.html模板中的<head>和</head>之间添加加载jQuery库的JS代码:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
  2. 然后再在default.html、single.htm、catalog.html、tags.html、gestbook.html、search.html模板中的jQuery库JS代码之后添加以下代码:

    <script type="text/javascript">
    ///友情链接图标favicon
    jQuery(document).ready(function($){ 
    $(".blogroll a").each(function(e){
    	$(this).prepend("<img src=http://www.google.com/s2/favicons?domain="+this.href.replace(/^(http:\/\/[^\/]+).*$/, '$1').replace( 'http://', '' )+" style=float:left;padding:5px;>");
    }); 
    });
    </script>
  3. 保存文件后,重建文件,刷新首页即可。
    z-blog

提示:如果只有首页显示友情链接,除了default.html文件外,其它文件不用添加相关JS代码。

扫码添加微信

13013082126 扫描微信 建站咨询 优化咨询