知名WordPress博主Zww大神的高质量WordPress评论及文章代码
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

Zww 大神已经很久没有开发 WordPress 主题了,现在很多年轻的开发者可能都不认识 Z 大了,不过如果是水煮鱼、木木木木木这辈的,应该都相熟。Z 大优化的 WordPress 代码,一直在使用,虽然都是老代码,对于一些想要自行修改 WordPress 主题的童鞋还是很有帮助。
内容 1 最新评论代码 - Recent Comments 2 最新文章代码 - Recent Posts 3 随机文章代码 - Random Posts 4 最热文章代码 - Hot Posts 4.1 相关文章最新评论代码 - Recent Comments
这个是支持显示 gravatar 头像的。代码如下,使用 sql 实现的,对中文支持非常好,但英文博客就还是算了。
<h2>Recent Comments</h2> <ul> <?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,16) AS com_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 post_password = '' AND user_id='0' ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach ($comments as $comment) {$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 24).strip_tags($comment->comment_author).":<br />" . " <a h=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"on " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a>...</li>";} $output .= $post_HTML; echo $output;?> </ul>说明:comment_content,1,16 中的16是每个留言的文字摘取数量;……ORDER BY comment_date_gmt DESC LIMIT 10 中的10是留言数量
最好用 css 自定义一下 gravatar 图片位置,可以参考一下我的:
#sidebar img.avatar{float:left;position:relative;border:1px solid #ddd;padding:1px;margin-right:5px;}这是之后z大神根据willin版本修改过的。
(willin的加了头像缓存后的代码,我这的是没有加缓存的)
<h3>Recent Comments</h3><ul class="recentcomments"><?php //2010/4/25 更新 by willin$limit_num = '8'; //这里定义显示的评论数量$my_email = "'" . get_bloginfo ('admin_email') . "'"; //这里是自动检测博主的邮件,实现博主的评论不显示$rc_comms = $wpdb->get_results(" SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content 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 post_password = '' AND comment_author_email != $my_email ORDER BY comment_date_gmt DESC LIMIT $limit_num ");$rc_comments = '';foreach ($rc_comms as $rc_comm) { //get_avatar($rc_comm,$size='50')$rc_comments .= "<li>". get_avatar($rc_comm,$size='50') ."<span class='zsnos_comment_author'>" . $rc_comm->comment_author . ": </span><a h='". get_permalink($rc_comm->ID) . "#comment-" . $rc_comm->comment_ID//. htmlspecialchars(get_comment_link( $rc_comm->comment_ID, array('type' => 'comment'))) // 可取代上一行, 会显示评论分页ID, 但较耗资源. "' title='on " . $rc_comm->post_title . "'>" . strip_tags($rc_comm->comment_content). "</a></li>\n";}$rc_comments = convert_smilies($rc_comments);echo $rc_comments;?></ul>使用:直接贴到sidebar.php即可使用。
由于这次willin的没有加截断函数,所以要靠css的overflow:hidden隐藏。参考我这个主题写的css
#sidebar .recentcomments img.avatar{width:16px;height:16px;float:left;position:relative;border:1px solid #ddd;margin:0 5px 0 0;padding:1px;}#sidebar ul.recentcomments{list-style:none;padding-left:0;}#sidebar ul.recentcomments li{margin:5px 0 0;line-height:20px;height:20px;overflow:hidden;}最新文章代码 - Recent Posts
这代码应该是来自帕兰映像的了,可以直接去老帕那看,他那好东西很多,嘿嘿。代码如下:
<h2>Recent Posts</h2> <ul> <?php $myposts = get_posts('numberposts=10&offset=0&category=0'); foreach($myposts as $post) : setup_postdata($post); ?> <li><span><a h="<?php%20the_permalink();%20?>"><?php the_title(); ?></a></span> <span><?php the_time('Y/m/d'); ?>.</span> </li> <?php endforeach; ?> </ul>说明:numberposts 是文章数量
随机文章代码 - Random Posts
同上也是来自帕兰映像
<h3>Random Posts</h3> <ul> <?php $rand_posts = get_posts('numberposts=10&orderby=rand'); foreach( $rand_posts as $post ) : ?> <!--下面是你想自定义的Loop--> <li><a h="<?php%20the_permalink();%20?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>最热文章代码 - Hot Posts
忘了哪里搜来的,那么又是来自互联网!很好用,代码如下:
<h2>Hot Posts</h2> <ul> <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10"); foreach ($result as $post) { setup_postdata($post); $postid = $post->ID; $title = $post->post_title; $commentcount = $post->comment_count; if ($commentcount != 0) { ?> <li><a h="<?php%20echo%20get_permalink($postid);%20?>" title="<?php echo $title ?>"> <?php echo $title ?></a> (<?php echo $commentcount ?>)</li> <?php } } ?> </ul>[WordPress]历史优惠活动内容
猜你可能想看的VPS
- extravm→俄罗斯 VPS $5 月 KVM 虚拟 1G 内存 1 全球[VPS测评]
- CloudCone→$17.5 年 1.5GB 内存 45GB 空间 1虚拟空间(主机)
- 新商家慎重-Rabbithosts – 4 核 8G 内存 40G 硬盘全球[VPS测评]
- HawkHost→$5 月 Cloud-1GB 20G SSD 1TB 全球[VPS测评]
- CloudCone→$15 年 KVM-512MB 10GB 1TB 洛全球[VPS测评]
- 腾讯云双十一提前购→1C2G1M 年付 88 元 2C4G5M 三年仅 全球[VPS测评]
- 特价 碳氧云→6 核 CPU 6G 内存 80G 硬盘 6Mbps 不限香港VPS[主机]
- OVZ 谨慎-Ethernetserver→$12 年 1 核 1G 1美国VPS[主机]
- 德讯电信→台湾大宽带独立服务器 不限流量 到国内速度飞快 价格低至¥16独立服务器[U]
- WordPress通过根据评论数量判断是否显示评论者链接全球[VPS测评]
- WordPress如何手动还原到旧版本全球[VPS测评]
- DMIT LAX.sPro高防套餐八五折 2G内存/100Mbps带宽/全球[VPS测评]
- WordPress根据最后一次评论时间判断是否显示评论者链接全球[VPS测评]
- 迅捷 PDF 转换器6.9版本永久授权分享注册机 破解版全球[VPS测评]
- 通过腾讯云函数每天定时签到京东领取京豆教程全球[VPS测评]
- VirMach 日本东京 AMD 便宜 VPS 补货,$30起/2年,I日本VPS[主机]
- 2019黑五: ZeptoVM 欧洲CN2 → 1C 512M RAM 全球[VPS测评]
- 精编案例丨游戏行业转型升级迫在眉睫,云计算助力打造下一代游戏体验全球[VPS测评]
- 亚马逊卖家与广告流量之间的博弈才刚刚开始?品牌卖家如何冲破广告之困...全球[VPS测评]
- 阿里云服务器一年价格多少钱?阿里云服务器报价全球[VPS测评]
- 2023年 IDC市场结构和方向的深度分析全球[VPS测评]
- 2.45亿、成都公安(大数据基座-服务器)采购:神码、虹信、海康、超聚变全球[VPS测评]
- sugarhosts首推DECADE云服务器,香港云服务器,1核512M香港VPS[主机]
- 恒创科技:免备案香港/美国云服务器低至2.5折,仅需220元/年美国VPS[主机]
- 什么是linux面板?常见的Linux控制面板有哪些?全球[VPS测评]
- 从阿里云七代云服务器,谈云计算四大趋势全球[VPS测评]
- 印象云:1核/1G/40G固态/800G/50Mbps/洛杉矶高防vps全球[VPS测评]
- LOCVPS:香港vps八折优惠中,双十一预热,充值充600送150,六香港VPS[主机]
- 桔子数据:香港CN2大带宽云服务器28元/月_1核/1G/10M带宽/C香港VPS[主机]
- 魔方云:2021春节促销_香港CN2/美国CN2全年最高折扣75折/香港美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-226599.html











