知名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
- 促销 Hostdare→85 折促销优惠 CN2 和 CN2 GIA 线全球[VPS测评]
- javascript 验证以指定字符或字符串开头的正则表达式全球[VPS测评]
- 微信支付接入报错→invalid spbill_create_ip全球[VPS测评]
- invs→4.1 元 月 512MB 内存 5GB 空间 不限流量 10虚拟空间(主机)
- 促销 ZJI→香港葵湾独立服务器补货 终身六折优惠中 CN2+BGP 直独立服务器[U]
- 1fichier→€15 年 100TB 空间 支持 FTP WebDA虚拟空间(主机)
- 不推荐-anyunweb→20 元 月 1GB 内存 50GB 空间 不虚拟空间(主机)
- 阿里云 - 轻量应用服务器香港数据中心线路非直连香港VPS[主机]
- Dataplugs 多线通香港服务器五折起,企业级 E3 E5 服务器,香港VPS[主机]
- dogyun→挑战低价-15 元 月 美国 cn2 gia VPS KV美国VPS[主机]
- 搬瓦工又一次关闭免费更换IP服务全球[VPS测评]
- 如何实现通过Gzip压缩实现WordPress站点加速的各种方法全球[VPS测评]
- CumulusCloud → 5€ 月 2C4G20G硬盘 法国 1Gb全球[VPS测评]
- 谷歌浏览器网址如何显示http,www,Chrome谷歌浏览器恢复地址栏全球[VPS测评]
- 世界杯季疫情突发,跨境电商订单排队,义乌商人面临难题全球[VPS测评]
- wordpress 上传附件报错 “抱歉,出于安全的考虑,不支持此文件类全球[VPS测评]
- 阿里云服务器一年价格多少钱?阿里云服务器报价全球[VPS测评]
- 腾讯会议故障了 提示:会议发生异常请重新加入会议全球[VPS测评]
- RFCHost:1核1G洛杉矶vps/15GB空间/1TB流量/KVM/虚拟空间(主机)
- CIO和其他IT领导者充分利用边缘计算增强业务的4个关键全球[VPS测评]
- 香港服务器租用哪里有?便宜的香港服务器租用香港VPS[主机]
- 好朋友51WORLD启动“地球克隆计划5”,我要去元宇宙参加了全球[VPS测评]
- 如何更改WHMCS默认后台路径让WHMCS系统更安全全球[VPS测评]
- tudcloud,香港vps终身八折$7.76/月起,1核1G内存,香港香港VPS[主机]
- 悦智网络:香港cn2 VPS阿里云线路,四川德阳高防vps,大连高防vp香港VPS[主机]
- 欧路云:香港/加拿大/法国/新加坡vps全线产品8折优惠,适用于新购/续香港VPS[主机]
- HostXen:双十一新用户香港、日本vps,送20元代金券,充值300日本VPS[主机]
- 麻花云:香港CN2VPS月付19元起,安徽移动8核/16G/20M独服2香港VPS[主机]
- 缓解云计算人才焦渴,苏州工业园区用三年引得源头活水来全球[VPS测评]
- Linux系统下安装Java JDK全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-228023.html











