无插件为萄葡MM实现读者墙

> \(^o^)/ 刚才萄葡MM找我想实现读者墙,因为她的博客模版是不支持侧边栏的。
> 所以要用代码实现,且样式需要和我上次写的《在Li标签里实现图上字下排列的文章》中一样。

> 里面读者墙的函数代码,是来自万戈童鞋的《WordPress 免插件版侧边栏读者墙》文章。
> 因为萄葡MM的模板代码很有个性,所以函数代码不能放在 function.php 里的。

> P.s. 嘿嘿,我就喜欢有挑战性的东西,话说做这个的时候,自己的技术也有了突破了 O(∩_∩)O 。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$identity="comment_author";
$passwordpost = " AND post_password=''";
$userexclude = " AND user_id='' and comment_author != ''";
$approved = " AND comment_approved='1'";
$shownumber = 15;
$counts = $wpdb->get_results("SELECT COUNT(" . $identity . ") AS cnt, comment_author,
 comment_author_url,comment_author_email 
FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON 
($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE 
MONTH(comment_date)=MONTH(now()) and YEAR(comment_date)=YEAR(now())" .
$userexclude . $passwordpost . $approved . ") AS tempcmt GROUP BY " 
. $identity . " ORDER BY cnt DESC LIMIT " . $shownumber);
?>

> 首先把以上函数代码插入 sidebar.php 中的如下代码的下面。

1
<?php /* Please do not remove this line */ global $opt; ?>
1
2
3
4
5
6
7
8
9
10
<div class="sfbox"><h2>Featured Post</h2><div class="sfpost">
  <?php $my_query = new WP_Query('cat='.$opt['side_feature'].'&showposts='
.$opt['side_feature_num'].'&orderby=rand');
        while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
  <div class="introIMG"><?php echo get_the_image_link
(array('f_img','lead_img'),'thumbnail','/fdefault.gif'); ?></div>
  <?php endwhile; ?>
  </div>
  <div class="clear"></div></div>
	<?php endif; ?>

> 然后在以上代码的下面插入以下调用代码。嘿嘿,貌似有点绕口。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- Begin -->
<div class="sidebarbox"><h2>Reader Wall</h2><div class="sidebarbox">
<ul class="ffox_most_active">
<?php if ( $counts ) : foreach ($counts as $count) :
echo  '<li>' . '<a rel="nofollow" href="'. $count->comment_author_url 
. '" title="用户:' . $count->comment_author . ' (发表了'. $count->cnt 
. '条评论)"><div class="avatar">' .get_avatar($count->comment_author_email,32)
.'</div><p> '. $count->comment_author .'</p></a></li>';
endforeach; endif;
?>
</ul>
  </div>
  <div class="clear"></div></div>
<!-- End -->

> 然后在 style.css 文件底部插入如下的读者墙的CSS代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* ReaderWall */
.sidebarbox .sidebarbox .ffox_most_active li {
padding-left:0; width: 55px; float: left; background: none;
list-style: none; overflow: hidden; border-bottom: none;
}
.sidebarbox .sidebarbox .ffox_most_active img.avatar {
width: 32px; height: 32px; border: solid 1px #d4e7f2;
padding: 1px;
}
.sidebarbox .sidebarbox .ffox_most_active p {
padding-top: 1px; float: left; width: 37px; height: 13px;
line-height: 12px; text-align: center; white-space: nowrap;
overflow: hidden;
}

> 完成啦 O(∩_∩)O哈哈

Leave a comment

19 Comments.

  1. 一米 坐沙发!#1

    太绕口了啊,我都没看懂,我是说中文。

  2. 萄葡 坐板凳!#2

    谢谢达人~~o^.^o

  3. Auston Jary 躺地板!#3

    好强大~
    好厉害

  4. keon 天花板!#4

    我对图片里MM比较有兴趣~~坐下来看看代码先~~

  5. Awu 下水道!#5

    你怎么一直是这种格式的文章?

  6. 能不用插件实现还不要用插件实现比较好~
    代码果然还是那么强大的,只是那么多字母就解决了很大的问题~
    不得不说这是一种很奇特的语言~

    • @exia,
      呵呵 ~
      其实也差不多 ~
      因为如果用了插件的话 ~
      插件就会告诉程序要把我写的这段代码插入到侧边栏 ~
      而且可以使用后台的小工具功能任意拖动呢 ~
      ----------
      的确 代码很奇特 ~
      一种很神奇的语言 ~
      ╮(╯▽╰)╭ 我快变成代码控鸟 ~

  7. 来膜拜一下 邪罗刹 达人~~

  8. 这个不错,正好有用

Leave a Reply

:evil: :razz: :wink: :rolleyes: :redface: :cry: :biggrin: :lol: :idea: :mrgreen: :mad: :exclaim: more »

[ Ctrl + Enter ]