WordPress给模板添加友情链接页面

/ 6评 / 0

因为这个模板没有友情链接页面,而我之前与其他人换过友情链接,我就有必要自己添加一个友情链接页面。

首先,复制page.php文件并剪贴重命名为link-page.php,打开link-page.php找到<?php the_content(); ?>替换为如下代码

<div class="links">
 <?php
 $bookmarks = get_bookmarks('title_li=&orderby=rand'); //全部链接随机输出
 if ( !empty($bookmarks) ){
 foreach ($bookmarks as $bookmark) {
 $friendimg = $bookmark->link_image;
 echo '<a class="link" href="' . $bookmark->link_url . '" target="_blank" style="margin: 0;">
<img src="'. $bookmark->link_image. '" style="cursor: pointer; display: block; margin: 0 auto;">
<div class="sitename">'. $bookmark->link_name .'</div>
<div class="siteinfo">' . $bookmark->link_description . '</div></a>'
;
 }
 }
 ?>
</div>

如果你想要在友情链接页面显示页面文章内容的话,在</div>后加入<?php the_content(); ?>即可,然后你只需要在后台的链接中添加链接即可

没有链接的,打开你的functions.php,在结尾添加如下代码即可

add_filter( 'pre_option_link_manager_enabled', '__return_true' );

完成如上步骤后你只需要新建一个页面使其别名为links即可看到你的友情链接页面,以及你添加的友情链接了!

什么?不美观?在你的css文件中添加如下代码即可

.link{outline: none; color: #444;float: left; width: 50%; text-align: center; border-radius: 5px; transition: all .3s ease-in-out;margin-top: 10px;cursor: pointer;}
.link:hover{background-color: #eee}
.link img{width: 70px; height: 70px; border-radius: 70px; margin: 5px 10px !important; transition: all .3s ease-in-out; float: left;}
.link .sitename{font-weight: bold; font-size: 20px; margin-top: 10px;cursor: pointer;}
.link .siteinfo{color: #777; margin-top: 10px; overflow: hidden; text-overflow: ellipsis;}
.links a{text-decoration: none;}

文章若未注明则均为原创,转载请注明来源自豆博客-WordPress给模板添加友情链接页面

6条回应:“WordPress给模板添加友情链接页面”

  1. Turkije Visums说道:

    Wow, fantastic weblog layout! How lengthy have you been blogging for?
    you made running a blog glance easy. The full glance of your website is great, as well as the content!

    • Mr.Bean说道:

      @Turkije Visums Yes, my friend, I like simple things. I have been blogging for more than a year. This blog uses Adams theme of WordPress. I really feel like it and your comments. This makes me continue to write. I hope you can see and comment on it regularly.(My English is not good,So the above content is translated using Baidu translation, including this one.)

  2. Turkije Visums说道:

    I got this web site from my buddy who informed me about this
    web site and at the moment this time I am browsing this site and reading very informative posts at this time.

  3. lubin说道:

    Hey there! This post couldn’t be written any better!

    Reading this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this
    write-up to him. Fairly certain he will have a good read.
    Thanks for sharing!

Mr.Bean进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注