知名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
- 便宜 $1.75 月 2 核 CPU 3G 内存 50G SSD 3T 全球[VPS测评]
- ZJI 香港葵湾服务器六折优惠,香港 CN2 4C 站群 美国圣何塞 G站群服务器[IP]
- veesp→$1 月 KVM-512MB 10GB 100GB 圣彼得堡全球[VPS测评]
- FastCache→有香港直连节点 100GB 通用流量包 18.8 元香港VPS[主机]
- Linode - 新增独立 CPU 实例 Dedicated CPU I独立服务器[U]
- NTUP→$12 年 KVM-512MB 5G SSD 1G 无限流量 全球[VPS测评]
- ITLDC - BlackFriday 黑五 VPS4 折促销 9 机房全球[VPS测评]
- 一体云→镇江挂机宝 2H1G 3 元 月 高防服务器 16 核 32GB全球[VPS测评]
- centos6 安装 transmission+flexget 实现 P全球[VPS测评]
- HKServerSolution→299 元 月 2G 内存 20GB 虚拟空间(主机)
- KMS 激活 Windows OfficeWINDOWS
- bootstrap-table 多行重复表头的解决办法全球[VPS测评]
- photoshop 打开图片提示→无法完成请求 因为找到不知名的或无效的全球[VPS测评]
- 便宜 $20 年 1 核 512M 内存 10G 硬盘 1T 流量 1G全球[VPS测评]
- Chrome插件Personal Blocklist全球[VPS测评]
- RAKsmart双十一活动 每天10台独服月付30刀秒杀,注册就送10刀全球[VPS测评]
- 10g.biz 洛杉矶三网直连/CN2GIA独服 七折 $97.3起/月全球[VPS测评]
- 快速云:怎么连接vps?VPS的用途有哪些?全球[VPS测评]
- 如何根据业务需求选择合适的云服务器配置?全球[VPS测评]
- CentOS 7.x 系统安装和配置redis-7.0.4集群全球[VPS测评]
- 云服务器和服务器各有什么优缺点?全球[VPS测评]
- 硅云:香港云服务器2核2G5M促销1999元/3年起,香港虚拟主机1G空虚拟空间(主机)
- 实例 GIA0910629396 重启失败,原因:sudo: unabl全球[VPS测评]
- 云计算拯救互联网巨头:谁抢跑,谁追赶?全球[VPS测评]
- 六六云:美国cera机房CN2 GIA高防/香港CN2 GIA建站/CM美国VPS[主机]
- 翔云网络怎么样?香港云服务器优惠99/月,国内4核4G高防服务器6800香港VPS[主机]
- gcorelabs:KVM主机€1.08/月起,香港/俄罗斯/亚太/欧美香港VPS[主机]
- EdgeNAT,香港CN2+BGP vps 带宽5M 月付72元香港VPS[主机]
- 六一云:香港CMI VPS,10G防御,1核/1G/40G SSD/15香港VPS[主机]
- 56云服务器怎么样?56云服务器价格和优势是什么?全球[VPS测评]
转载请注明原文地址:http://www.motoll.com/read-226599.html