用到了WordPress性能函数Query_post()的一种初级用法,就是获取本周或当月或最近30天评论最多的肯定数量的日志。
应用办法是将以下各段代码搁置到需求显示最热日志的主题模板文件中适当的地位即可,如边栏(sidebar.php)。
一切工夫内评论最多日志
<ul> <?php query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC'); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
这段代码默许显示前10篇评论最多的日志,数量10可修正为其它数值。
本周评论最多日志
要显示本周评论最多日志,咱们就能够应用如下的代码,也就是在后面代码的根底上再增加一些额定的参数来完成:
<ul> <?php $week = date('W'); $year = date('Y'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC&year=' . $year . '&w=' . $week); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
最近30天评论最多日志
<ul> <?php function filter_where($where = '') { //posts in the last 30 days $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC'); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
“30 days”能够依据需求修正为其余值(如“1 year”, “7 days”, 等)。
本月评论最多日志
相似地,显示当月评论最多的日志,能够应用上面的代码:
<ul> <?php $month = date('m'); $year = date('Y'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC&year=' . $year . '&monthnum=' . $month); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
以上就是安达网络工作室关于《WordPress 实现文章评论排行榜》的一些看法。更多内容请查看本栏目更多内容!
本文实例讲述了Dedecms待审核章在列表页显示的办法。分享给大家供大家参考。详细剖析如下: 昨天我写了一个...
明天,想着在我机器上测试一下wordpress,尽管之前也有这个开源的顺序,可是不断没有装置呢,再加上最近不断...
什么是自定义post? 不要想当然的以为这里的post就是就是指博客中的文章,它只不过是一个文章类的代理词...
获取特定分类文章数 有时分咱们想获取某个分类(category)下的文章数目,以便在博客的某个中央显示进去。上面...
在以前的代码中,咱们仅仅应用add_shortcode函数来把短代码注册到wordpress中,在文章页应用the_content来显...
但在制造主题的时分,每个用户的需要都不同,而且你也不可能在文章下方增加太多的内容。因而让用户能自定义...