知名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
- 搬瓦工→DC6 机房 CN2 GIA 线路推出 10Gbps 带宽 VP全球[VPS测评]
- PacificRack 便宜美国 vps 五月特惠,洛杉矶 QN 机房,美国VPS[主机]
- 特别烂-Letbox→洛杉矶 VPS 2 核 2G 内存 20G NVM全球[VPS测评]
- Centos 下安装配置 Jenkins 环境全球[VPS测评]
- drServer→$14.5 月-C2750 8GB 2TB 100M 全球[VPS测评]
- 腾讯云 6Mbps 带宽云服务器三年付 1499 元,2Mbps 带宽云全球[VPS测评]
- 移动端网页点击电话号码自动转到拨号页面及发送短信页面的方法全球[VPS测评]
- php 生成随机颜色最简单办法 php 一句话代码生成随机颜色全球[VPS测评]
- $4 月 512M 内存 20G SSD 1Gbps 不限流量 KVM 日本VPS[主机]
- 疯狂猜成语 图猜成语一个人左边是一个天使右边是一个恶魔是什么成语?全球[VPS测评]
- 520 欢庆优惠 VpsMS→洛杉矶安畅 GIA CN2 线路 VPS 全球[VPS测评]
- 优惠 JGKVM→洛杉矶 CN2 GIA 套餐补货 年付低至 189 元香港VPS[主机]
- dedicatserver.ro罗马尼亚抗诉VPS 2核4G内存/30G全球[VPS测评]
- WordPress博客网站代码实现右键菜单功能修改全球[VPS测评]
- Terrahost挪威AMD不限流量VPS六五折优惠,Ryzen 595全球[VPS测评]
- 篱落主机 香港独立IP虚拟主机 年付90元 VPS 香港 BGP 多线机独立服务器[U]
- 搭建WordPress博客要如何选择域名全球[VPS测评]
- CloudCone 512 内存 20G HDD 1T流量 洛杉矶 MC全球[VPS测评]
- Scorpioud 1核心 2G内存 15G SSD 100M不限流量 全球[VPS测评]
- 快速云:云服务器vps的区别是什么云服务器和vps哪个比较好2022-0全球[VPS测评]
- 蓝米云:美国cera vps/香港cn2vps套餐,1核2G/40G/1美国VPS[主机]
- 日主机,便宜美国CN2高防VPS¥19/月起,1Gbps带宽,香港多IP站群服务器[IP]
- 数字化东风已来,亚马逊云科技跨境电商合作企业招募大会即将开启全球[VPS测评]
- 56云服务器怎么样?56云免备案香港云服务器价格多少钱?香港VPS[主机]
- 亿速云11.11上云狂欢节活动:2核4G国内/香港云服务器,价格999元香港VPS[主机]
- UCloud海外节点vps活动:香港、台湾等全球14个机房1折起,最低仅香港VPS[主机]
- 微基主机:1核1G香港云服务器,100Mbps/香港CN2直连/KVM/香港VPS[主机]
- 外贸无界烟台市有多少跨境电商?烟台跨境电商开发平台,烟台跨境电商选品全球[VPS测评]
- 云基:香港/洛杉矶CN2 GIA服务器促销,3750元/月起;欧洲大盘鸡香港VPS[主机]
- 企鹅小屋怎么样?深港IPLC专线销售 500M大带宽/2核1G内存/55全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-226599.html











