WordPress网站设置侧栏“最近访客”小工具美化版
1.访客代码function.php文件
//最近访客-xiaohulizyw.com
function Autofirst($af){
global $wpdb;
$queryaf="select comment_author, comment_author_url, comment_date from $wpdb->comments where comment_ID in (select max(comment_ID) from $wpdb->comments where comment_approved='1' and comment_author_url !='' and user_id='0' GROUP BY comment_author_email) ORDER BY comment_date DESC LIMIT $af";
$wally = $wpdb->get_results($queryaf);
foreach ($wally as $commentaf){
$tmpy= "comment_author_url."\">✪".$commentaf->comment_author.",";
$outputy .= $tmpy;
}
$outputy = "".$outputy."";
echo $outputy ;
}
2.添加小工具样式,主题文件style.css
/*****最近访客-xiaohulizyw.com*****/
.demo{margin:0 auto;}
.taglist{padding:10px;}
.taglist a{padding:0 3px 0 0 !important;font-size:15px; display:inline-block;white-space:nowrap;}
.taglist span {padding:3px;font-size:15px!important;color:#004687}
a.size1{padding:1px;font-size:15px;color:#ea4563;}
a.size1:hover{color:#E13728;}
a.size2{padding:1px;font-size:15px;color:#004687;}
a.size2:hover{color:#E13728;}
a.size3{padding:1px;font-size:15px;color:#9F35FF;}
a.size3:hover{color:#E13728;}
a.size4{padding:1px;font-size:15px;color:#f99f13;}
a.size5:hover{color:#B46A47;}
a.size5{padding:1px;font-size:15px;color:#d378ec;}
a.size5:hover{color:#E13728;}
a.size6{padding:1px;font-size:15px;color:#89b6fe;}
a.size6:hover{color:#E13728;}
3.在主题目录B2/common/,新建文件:caise-fangke.php,添加以下代码
<script type="text/javascript">
$(document).ready(function(){
/*随机颜色*/
var tags_a = $("#tags").find("a");
tags_a.each(function(){
var x = 9;
var y = 0;
var rand = parseInt(Math.random() * (x - y + 1) + y);
$(this).addClass("size"+rand);
});
});
</script>
<div class="demo">
<div class="taglist" id="tags">
<?php Autofirst(25);?>
</div>
</div>
4.代码调用
<?php get_template_part( 'common/caise-fangke' ); ?>
声明:本站部分文章来源于网络,如有危害到您的合法权益请联系客服