知名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
- tmhhost→香港 cn2 服务器(物理机) 400 元 月 X345香港VPS[主机]
- 双十一 微基主机预热活动→韩国机房双 E5-2630L 32G 韩国VPS[主机]
- 商家投稿 ¥50 月 2 核 CPU 2G 内存 180G 硬盘 5Mb全球[VPS测评]
- 疯狂猜成语 图猜成语一片草和一个人被拦腰斩断是什么成语?全球[VPS测评]
- 腾讯云采购季最后一天,云服务器低至 299 元 3 年,2 核 4G 4全球[VPS测评]
- 新商家慎重–XenSpec→$2.4 月 KVM-1GB 10GB 无限全球[VPS测评]
- 活动倒计时 Virmach→$15 年的 KVM 特价促销方案即将结束 全球[VPS测评]
- Zcloudme→$59.5 月 2*E5-2620v3 32G 内存 香港VPS[主机]
- spinservers→$99 月 2*e5-2630L v2 64g 美国VPS[主机]
- 腾讯云年末有礼→国内云服务器 1C2G1M 年付 128 元 2C4G6全球[VPS测评]
- 阿里云 2020 年 1 月促销:国内 香港云服务器 2 核 8G5M1香港VPS[主机]
- 从Alpnames域名注册商跑路看我们应该如何选择域名注册商全球[VPS测评]
- WordPress插件:有字库插件美化文章标题和内容全球[VPS测评]
- VDSCOM → 7.99$ 月 1C1G10G硬盘 1Gbps不限流量美国VPS[主机]
- DomaiNesia 5$ 印尼雅加达VPS 测试(踩坑)全球[VPS测评]
- hizhosting-土耳其 39里拉 月 2核2g内存40G硬盘 不限全球[VPS测评]
- Hostsolutions.ro → 五折- 1G 1T HDD 10T全球[VPS测评]
- 阿里云轻量级服务器低至144年付全球[VPS测评]
- WikiHost 洛杉矶INAP线路VPS 可NF HULU全球[VPS测评]
- Kimsufi KS3(法国) & KS7(CA) 促销全球[VPS测评]
- 江苏高防服务器哪里买?宿迁BGP、宿迁双线高防服务器的价格全球[VPS测评]
- 明恒互联:双旦同庆活动开启,100G国内高防云售价116元/月,香港云主香港VPS[主机]
- 详细介绍vps云服务器及其作用全球[VPS测评]
- tmhhost:8折优惠,美国cn2 gia高防vps,香港NTT vp美国VPS[主机]
- 香港的云服务器值得租用吗?有什么好处?香港VPS[主机]
- anyhk香港HKT商宽NAT VPS,1Gbps无限流量,终身8折¥3香港VPS[主机]
- kvmloc:E5-26XX/16G/1T HDD/20Mbps不限流量日本VPS[主机]
- 2022年黄河流域跨境电商博览会将于8月26日至28日在青岛西海岸新区举全球[VPS测评]
- 六六云:1核1GB/15GB空间/1T流量/100Mbps/KVM/香港虚拟空间(主机)
- 易探云:独立IP香港云服务器租用,香港vps海外云主机BGP线路/CN2独立服务器[U]
转载请注明原文地址:http://140.238.13.167:12355/read-227286.html











