收集一波常见的加速NPM包的CDN,发现有些还是挺好用的,基本上可以替代unpkg、jsdelivr,用来做博客或者网站加载NPM使用还是可以的。......
WordPress 实现文章评论排行榜
用到了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网站文章ID不连续如何解决?笔记已测试详细阅读
对于WordPress网站文章ID不连续的问题困扰了我很久,今天将WordPress文章ID不连续的原因和具体解决办法做详细的说明。 WordPress文章ID不连续的原因: 用WordPress做网站的站......
2023-08-17 24
-
wordpress建站教程:文章自动调用特色图片详细阅读
继续分享wordpress建站教程。我们在日常更新wordpress网站文章时基本都需要手动添加文章的缩略图,一般是根据文章内容来添加,虽然麻烦一点,但效果更好,对普通的企业wordpress外......
2023-08-14 66