简而言之就是左侧的最近访客小工具
方法一丶多说有一个最近访客的小工具,显示最近的访客列表,这个比较不错,很多人都是用的多说这个评论系统,但是多说是登陆用户,有数据可以操作。本站采用的就是多说自带的工具。
方法二丶原生wp函数无法做到数据查询,所以只能考虑一些其他的方法,调用最近留言的访客,当然,每个人只会显示一次。。代码如下,把代码放到functions.php
中
function bigfa_recent_visitors($limit=5){
$comments=get_comments(array('number'=>100,'status'=>'approve','type'=>'comment'));
$wpchres=get_option('blog_charset');
$exclude_emails=array(get_bloginfo('admin_email'));
$ilostoutput='';
$i=1;
$loadmail=array('');
foreach($comments as $comment){if(in_array($comment->comment_author_email,$exclude_emails))continue;
if(in_array($comment->comment_author_email,$loadmail))continue;
$bigfaoutput.='<a href="'.get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID.'" title="'.stripslashes($comment->comment_author).'"><span class="bigfa_recent_visitors">'.get_avatar($comment,64).'</span></a>'."n";
$loadmail[]=$comment->comment_author_email;
if($i==$limit){break;}$i++;}$loadmail=array('');
echo ent2ncr($bigfaoutput);}
这是核心函数,接着要把这个做成小工具,下面的代码放在functions.php中,里面的12是访客显示数量
class bigfa_recent_visitors extends WP_Widget {
function bigfa_recent_visitors() {
$widget_ops = array('description' => '最近访客小工具By Shknn');
$this->WP_Widget('bigfa_recent_visitors', '最近访客', $widget_ops);
}
function widget($args, $instance) {
extract($args);
echo $before_widget;
?>
<h3>最近访客</h3>
<div>
<?php bigfa_recent_visitors($limit=12);?>
</div>
<?php
echo $after_widget;
}
function form($instance) {
global $wpdb;
?>
<p>该工具没有选项!</p>
<?php
}
}
add_action('widgets_init', 'bigfa_recent_visitors_init');
function bigfa_recent_visitors_init() {
register_widget('bigfa_recent_visitors');
}
然后加上一个样式CSS,美化一下,自行添加新的CSS或是放在现有的CSS里
.bigfa_recent_visitors{border: 2px solid #FFFFFF;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.21), 0 1px 3px rgba(0, 0, 0, 0.34) inset;display: block;float: left;height: 48px;margin: 3px 6px 5px 7px;overflow: hidden;width: 48px;}
2014年10月03日 下午7:40 沙发
图片和代码溢出。
来自外部的引用: 1