1 內(nèi)頁友情鏈接創(chuàng)建方法
WordPress可以通過后臺添加和管理友情鏈接,但它沒有內(nèi)頁友情鏈接的功能。
考慮到WordPress建站的易用和準(zhǔn)確性,決定使用 wp_list_bookmarks 友情鏈接函數(shù)來調(diào)用,使用單獨的內(nèi)頁模板來實現(xiàn)。
具體示例可參考我們網(wǎng)站的內(nèi)頁鏈接頁面?▼
第 1 步:創(chuàng)建新頁面
第 2 步:復(fù)制 page.php 文件
第 3 步:找到文章內(nèi)容顯示函數(shù)
在 page-links.php 文件中,找到文章內(nèi)容顯示函數(shù)?▼
<?php the_content(); ?>
在它下面,添加以下代碼 ▼
<div class="page-links"> <h3>內(nèi)頁鏈接</h3> <ul> <?php $default_ico = home_url().'/links_default.ico'; //默認(rèn) ico 圖片位置 $bookmarks = get_bookmarks('title_li=&categorize=0&category=64,193&orderby=rand'); //如果你要輸出某個鏈接分類的鏈接,更改一下get_bookmarks參數(shù)即可 /*如要輸出鏈接分類ID為5的鏈接title_li=&categorize=0&category=5&orderby=rand */ /*全部鏈接隨機(jī)輸出 title_li=&orderby=rand */ if ( !empty($bookmarks) ) { foreach ($bookmarks as $bookmark) { echo '<li><img src="', $bookmark->link_url , '/favicon.ico" onerror="javascript:this.src=\'' , $default_ico , '\'" /><a href="' , $bookmark->link_url , '" title="' , $bookmark->link_description , '" target="_blank" >' , $bookmark->link_name , '</a></li>'; } } ?> </ul> </div>
為了更美觀,你可以定義 page-links 的class樣式。
以下是我們所使用主題的CSS樣式?▼
/*內(nèi)頁鏈接*/ .page-links{overflow:hidden;margin:0 0 24px;padding:0;} .page-links h3{border-bottom:1px solid #bfbebe;text-align:center;margin:0;} .page-links ul{margin:0;padding:5px 0 0 0;} .page-links ul li{float:left;width:150px;line-height:16px;height:16px;margin:5px 5px 0;padding:0;list-style-type:none;} .page-links ul li:hover{background:#f2f2f2;} .page-links ul li img{width:16px;height:16px;margin:0 5px -2px 0;padding:0;border:none;}
到此大功告成!
希望我們網(wǎng)站( https://www.wordpressx.com/ ) 分享的《WordPress如何添加內(nèi)頁友情鏈接?3步創(chuàng)建內(nèi)頁鏈接》,對您有幫助。