闻心阁

一蓑烟雨看苍生,半壶浊酒笑红尘

wordpress笔记之读者墙+留言板

2011-09-27 约 1 分钟读完 搬砖秘籍

在wordpress中是不自带留言板功能的,之前一直是复制了一page.php然后自定义的留言板,后来发现了页面读者墙这个好玩的功能,索性就把读者墙和留言板这两个功能给放在了一起,效果还不错的说。

先加上这段

<?php
/*
Template Name: commentswall
*/
?>

在就是这段

<!-- start 读者墙 -->
                            <?php
                                $query="SELECT COUNT(comment_ID) 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 user_id='0' AND comment_author_email != '[email protected]' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 41";
                                $wall = $wpdb->get_results($query);
                                foreach ($wall as $comment)
                                {
                                    if( $comment->comment_author_url )
                                    $url = $comment->comment_author_url;
                                    else $url="#";
                                    $tmp = "<a href='".$url."' title='".$comment->comment_author." (".$comment->cnt."条评论)' target='_blank' rel='external nofollow'>".get_avatar($comment->comment_author_email, 40)."</a>";
                                    $output .= $tmp;
                                 }
                                echo $output ;
                            ?>
                            <!-- end 读者墙 -->

然后就是跟留言板集成了~这个就不用唠叨什么了吧~

当然同样的方法还有标签云页面:

wp_tag_cloud()

用到这个函数而已~

折腾笔记系列