> \(^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哈哈
太绕口了啊,我都没看懂,我是说中文。
@一米 , O(∩_∩)O哈哈 ~
那我以后应该用英文还是火星文?
谢谢达人~~o^.^o
@萄葡 , 不用呢 很有成就感来着 ~
O(∩_∩)O 哈哈 ~
好强大~
好厉害
@Auston Jary , 谢谢啦 O(∩_∩)O ~
其实也没有很厉害啦 ~
就是蛮感兴趣的 ~
我对图片里MM比较有兴趣~~坐下来看看代码先~~
@keon , 哈哈 ~
关于MM可以给你开个传送门:http://uuto.org/
你怎么一直是这种格式的文章?
@Awu,
我是说一行一行的,> ?
@Awu , 个人觉得有点像 命令行 Commands ~
呵呵 ~
@Awu , 我不小心写成这种文风 ~
就没改动了 ~
饿 你给我点建议看看?
我没办法了 ~ ╮(╯▽╰)╭
能不用插件实现还不要用插件实现比较好~
代码果然还是那么强大的,只是那么多字母就解决了很大的问题~
不得不说这是一种很奇特的语言~
@exia,
呵呵 ~
其实也差不多 ~
因为如果用了插件的话 ~
插件就会告诉程序要把我写的这段代码插入到侧边栏 ~
而且可以使用后台的小工具功能任意拖动呢 ~
----------
的确 代码很奇特 ~
一种很神奇的语言 ~
╮(╯▽╰)╭ 我快变成代码控鸟 ~
来膜拜一下 邪罗刹 达人~~
@萄葡 , 呵呵 没什么啦 ~
就是对代码兴趣浓厚 ~
@邪 罗刹,
真是代码控咩~
这个不错,正好有用
@bolo , 呵呵,别客气就用上吧,谢谢支持 ~