友情鏈接是一種在網(wǎng)站上展示其他網(wǎng)站鏈接的方式,通常用于互相推廣和建立合作關系。很多用戶在使用WordPress搭建網(wǎng)站時,不知道如何添加友情鏈接。本文將向大家介紹如何在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庫,可以直接調(diào)用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”需根據(jù)自己的模板更改。