WordPress添加友情链接

友情链接是一种在网站上展示其他网站链接的方式,通常用于互相推广和建立合作关系。很多用户在使用WordPress搭建网站时,不知道如何添加友情链接。本文将向大家介绍如何在WordPress中添加友情链接。

一、普通方法

1、建立一个新的模板页面,复制主题中的page.php文件,重命名为links.php。

在页面的顶部加入如下代码:

<?php
/*
Template Name: Links
*/
?>

再把类似下面的一段代码:

<div class="post-content"><?php the_content(); ?></div>

替换为:

<div class="lists"><p class="tips">站点随机排序</p><?php wp_list_bookmarks('orderby=rand&show_images=1'); ?></div>

替换后把links.php放在主题文件夹根目录,然后新建一个页面,在页面模板中选择刚建立的“Links”,保存。

2、添加CSS美化,例如:

.lists {padding: 5px; margin: 25px auto auto 0;}
.linkcat {font-size: 12px; font-weight: bolder; padding: 5px; margin-bottom: 15px; list-style: none; clear:both}
.lists li h2 {font-size:14px; margin-bottom: 15px; color: #99CC33; }
.listcat ul {margin-left: 20px;}
.linkcat ul li {float: left; margin-bottom: 20px; margin-left: 20px; padding: 4px 0 4px 6px; width: 150px; border: 1px solid #d9d9d9;}
.linkcat ul li a {color: #a4a4a4; text-decoration: none;}
.linkcat ul li a img {margin-right: 3px;}
.linkcat ul li a:visited {color: #a4a4a4;}
.tips {font-size: 14px; margin-bottom: 18px; margin-left: 5px;}

二、使用jQuery

1、加载jQuery库,可以直接调用google jQuery库:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

2、加载jQuery功能代码,注意jQuery闭合:

$(".linkpage a").each(function(e){
$(this).prepend("<img src=http://www.google.com/s2/favicons?domain="+this.href.replace(/^(http:\/\/[^\/]+).*$/, '$1').replace( 'http://', '' )+">");
});

这段jQuery的意思是遍历所有class为linkpage下所有的a标签,然后对该a标签添加img,其中是“.linkpage”需根据自己的模板更改。

广告合作
QQ群号:707632017

温馨提示:

1、本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。邮箱:2942802716#qq.com。(#改为@)

2、本站原创内容未经允许不得转裁,转载请注明出处“站长百科”和原文地址。

目录