WP无插件最新留言

WordPress, 前端笔记热度:1,185 ℃57 条吐槽阅读模式

这两天实在无聊所以又去折腾主题了,由于我自己把sidebar.php给禁用掉了,所有侧边栏的显示的东西全部都是在小工具里面添加的,这是很省事的一种方式,但是有一点不好,小工具里面只支持HTML代码,php的是无法识别的,所以网上的一些像无插件读者墙这种就无法放在侧边栏,于是我重新开启了我的sidebar,当然把原来的小工具也保留了下来,还是HTML代码我看起来比较亲切。

启用sidebar第一件事就是干掉WP-RecentComments这个插件,这确实是一个很好用的插件,我之所以干掉他是因为我需要一种更可爱的方式来展现最新评论,当然最好是可以自定义的方式了,所以非插件的方式是最好不过的了。

依然no picture no true

下面放我修改过的代码,原文出处在这里MOPVHS(其实这小子也是从别人那里搞来的。。。)

01 <ol id=“recentcomments”>
02 <?php
03 global $wpdb, $comments, $comment;
04 $comments = $wpdb->get_results(“SELECT comment_author, comment_author_email, comment_author_url, comment_ID, comment_post_ID, SUBSTRING(comment_content,1,65) AS comment_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ’1′ AND comment_type = ” AND comment_author != ‘N’ AND post_password = ” ORDER BY comment_date_gmt DESC LIMIT 16″);
05 if ($comments): foreach ($comments as $comment): $comment_author_N = $comment->comment_author;
06 if ($comment_author_N == “”) {$comment_author_N = “Anonymous”;}
07 $order = array (\r\n,\n,\r);
08 $order2 = array (\”,“\’”);
09 $replace = ;
10 $tmpstr = str_replace($order2, “”, str_replace($order, $replace, sprintf(‘%s’, strip_tags($comment->comment_excerpt))));
11 echo ‘<li><a title=”‘ . $comment_author_N . ‘在《’ . get_the_title($comment->comment_post_ID) . ‘》大声说’ . $tmpstr . ‘” id=”C_’ . $comment->comment_ID . ‘” href=”‘ . get_permalink($comment->comment_post_ID) . ‘#comment-’ . $comment->comment_ID . ‘” >’ . get_avatar($comment->comment_author_email, 51) . ‘</a></li>’;
12 endforeach;
13 endif;
14 ?>
15 </ol>

里面第四行里有一句是comment_author != ‘N’ ,目的是移除管理员的评论,你只要把N换成你自己的名字就行啦~~代码我只是精简了一下,没有用原文作者那种提示方式,而是使用了我自己的全站Tooltips气泡效果,反正已经使用了,不能浪费啊,正好顺便也放出来我的Tooltips效果代码吧,依然基于Jquery:

$(“a”).mouseover(function(e){
this.mytitle= this.title;
this.myhref=this.href;
this.title=“”;
var tooltips=“<div id=’tooltips’><p>”+this.mytitle+“</p><span>”+this.href+“</span></div>”
$(“body”).append(tooltips)
$(‘#tooltips’).css({“opacity”:“0.8″,“top”:(e.pageY+20)+“px”,“left”:(e.pageX+10)+“px”}).fadeIn(400)
}).mouseout(function(){
this.title=this.mytitle;
$(“#tooltips”).remove();
})
.mousemove(function(e){
$(‘#tooltips’).css({“opacity”:“0.8″,“top”:(e.pageY+20)+“px”,“left”:(e.pageX+10)+“px”})
})

如果你喜欢原作者的那种方式可以到上文原创那里去借用下代码,那种方式也是很不错的。

至此,大功告成,果然还是代码搞的比较好扩展,另外我针对Chrome浏览器做了一下小效果,有兴趣的童鞋可以用Chrome去看一下,也就是本文图中那种效果,虽然不是太完美,但是表现方式是自己想的,想法参考的是之前自己写的一篇文章里的demo,感兴趣的童鞋可以移步IE6下a:hover img去看一下,毕竟原创啊 (路过)

/*遥遥的梦想远远的人,遥遥远远我们的笑脸*/

相关日志-小站地图为你展开

上一篇 >>

57 条精彩的吐槽 在《 WP无插件最新留言 》

快来吐槽吧

貼張圖 您还可以输入300个字

(鬼脸) (额) (难过) (闷骚) (钱哇) (鄙视) (蛋定) (睡觉) (看看) (生气) (猪头) (汗) (晕) (无语) (无法表达) (微笑) (得意) (开怀) (媚眼) (囧) (嘿嘿) (哼) (哭泣) (不说话)
谁给我一滴水,我便回报他整个大海 关闭