WordPress教程

友情墙 - 自定义友情链接页面模板

阿里云

重要的事情只说一遍:这是本站首个自制的模板-友情墙,使用 wpdb 自定义去查询友情数据表,设计 CSS,首次弄这些,时间花得挺多呀,不熟悉 WP 的手册就是头痛的回事。要使用这种风格的友情链接,只需新建一个 PHP,把下面的代码复过去就行,然后再像其它页面一样添加一个,选上这个模板就 OK 了。

  1. <?php 
  2. /**
  3.  * Template Name: 友情墙
  4.  */
  5. get_header(); ?>
  6.  
  7. <main class="container">
  8. 	<div class="page-friends page-common row">
  9. 		<?php if (have_posts()): ?>
  10. 			<?php while (have_posts()) : the_post(); ?>
  11. 				<h1 class="page-title"><?php the_title(); ?></h1>
  12. 				<article class="page-content">
  13. 					<?php the_content(); ?>
  14. 				</article>
  15. 			<?php endwhile;  ?>
  16. 		<?php endif; ?>
  17. <style>
  18.     .clearfix {zoom:1;}
  19.     .clearfix:after {content:”.”;display:block;visibility:hidden;height:0;clear:both;}
  20.     .readers-list {list-style:none;}
  21.     .readers-list *{margin:0;padding:0;}
  22.     .readers-list li{position:relative;padding:10px;float:left;margin-top:20px!important;}
  23.     .readers-list li > a {
  24. 	border: 1px solid #eee;
  25. 	display: block;
  26. 	height: 85px;
  27. 	text-align: center;
  28. 	transition:all .5s;
  29. 	background: #f9f9f9;
  30. }
  31.     .readers-list li>a:hover{border-color:#e5e5e5;}
  32.     .readers-list a:hover em{top:45px;font-size:1.1em;}
  33.     .readers-list a:hover span{opacity:1;left:50%;}
  34.     .readers-list img{position:absolute;top:-30px;left:calc(50% - 30px);width:60px;height:60px;border-radius:50%;0px 0px 10px 5px #008EC2;box-shadow:0 0 6px 3px #0081B1;transition:all 1s;background:#fff;}
  35.     .readers-list a:hover img {
  36. 	-webkit-transform:scale(.7);
  37. 	-moz-transform:scale(.7);
  38. 	-o-transform:scale(.7);
  39. 	-ms-transform:scale(.7);
  40. 	transform:scale(.7);
  41. 	border-radius: 0;
  42. }
  43.     .readers-list em{
  44. 	position: absolute;
  45. 	top: 60px;
  46. 	-webkit-transform: translateX(-50%);
  47. 	left: 50%;
  48. 	font-style: normal;
  49. 	font-size: 1.2em;
  50. 	color: #818181;
  51. 	transition: all .3s;
  52. 	font-family: Helvetica,Arial,"PingFang SC","Microsoft YaHei","WenQuanYi Micro Hei","tohoma,sans-serif"
  53. }
  54. .readers-list span {
  55. 	position: absolute;
  56. 	left: 20%;
  57. 	bottom: 14px;
  58. 	overflow: hidden;
  59. 	white-space: nowrap;
  60. 	text-overflow: ellipsis;
  61. 	text-align: center;
  62. 	-webkit-transform: translateX(-50%);
  63. 	width: calc(100% - 30px);
  64. 	opacity: 0;
  65. 	transition:all .3s;
  66. 	color: #818181;
  67. 	font-family: Helvetica,Arial,"PingFang SC","Microsoft YaHei","WenQuanYi Micro Hei","tohoma,sans-serif"
  68. }
  69. @media(min-width:768px){
  70.     .readers-list li{width:25%;}
  71. }
  72. @media(max-width:767px){
  73.     .readers-list li{width:100%;}
  74. }
  75. </style>
  76. 		<div>
  77. 			<?php
  78. 			    global $wpdb;
  79.                 $qlink="select link_url,link_name,link_image,link_notes,link_description from wp_links where link_visible='Y' order by link_id"; 
  80.                 $links = $wpdb->get_results($qlink); 
  81.                 if(empty($links)) {echo '<p>暂无友链数据!</p>';}
  82.                 foreach ($links as $comment){   
  83.                 $tmp = "<li><a rel=\"nofollow\" title=".$comment->link_url." target=\"_blank\" href=\"/go?url=".$comment->link_url."\"><img src=".$comment->link_image." alt=\"\"><em>".$comment->link_name."</em><span>".$comment->link_notes."</span></a></li>";   
  84.                 $output1 .= $tmp;   
  85.                  }    
  86.                 $output1 = "<ul class=\"readers-list clearfix\">".$output1."</ul>";
  87.                 echo $output1; 
  88.             ?>
  89. 		</div>
  90. 		<?php
  91. 			if(comments_open()){
  92. 				comments_template();
  93. 			}else{
  94. 				echo "<h5>评论已经关闭</h5>";
  95. 			}
  96. 		?>
  97. 	</div>
  98. </main>
  99. <?php get_footer(); ?>
也想出现在这里?联系我们
创客主机

以下是最终的效果图:

友情墙 - 自定义友情链接页面模板

已有 749 人购买
查看演示升级 VIP立刻购买

收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!