
老是有人找狐狸求美化代码,其实狐狸有些美化代码也是从各位大佬那里扒过来的,很多东西都不好公布出来,近期我发现很多来求美化代码的都是做一些“子主题”的,子比有个通病,子主题是人是鬼都可以做,到处搜罗美化代码加到自己的主题插件上就圈钱。以后部份美化代码就通过赞助的方式获得吧。
效果演示


部署代码
- 添加的地方有两处,function.php(主站链接/wp-content/themes/zibll/function.php)
- 后台 >> 外观 >> 小工具 >> 实时预览。
自定义PHP(放到function.php 里)
//实现侧边栏文本工具运行PHP代码
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}
function zfunc_comments_users($postid=0,$which=0) {
$comments = get_comments('status=approve&type=comment&post_id='.$postid); //获取文章的所有评论
if ($comments) {
$i=0; $j=0; $commentusers=array();
foreach ($comments as $comment) {
++$i;
if ($i==1) { $commentusers[] = $comment->comment_author_email; ++$j; }
if ( !in_array($comment->comment_author_email, $commentusers) ) {
$commentusers[] = $comment->comment_author_email;
++$j;
}
}
$output = array($j,$i);
$which = ($which == 0) ? 0 : 1;
return $output[$which]; //返回评论人数
}
return 0; //没有评论返回0
};
function nd_get_all_view(){//文章总访问量
global $wpdb;
$count=0;
$views= $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key='views'");
foreach($views as $key=>$value){
$meta_value=$value->meta_value;
if($meta_value!=' '){
$count+=(int)$meta_value;
}
}return $count;
}
自定义HTML(小工具的文本里)
新老统计都会用到上方的自定义PHP代码,所以上面的代码是必须添加且一致的
配置演示

PHP 代码只能在文本上输入,其他输入会出现错误现象

点击文本,代码放到文本里即可,还有什么不懂的就在下方留言吧!
请登录后查看评论内容