有时候,我们在wordpress修改过程中,会用到按周浏览或者按月浏览的情况,尤其是需要做一些热门浏览的单页,要根据浏览次数获取本周或本月热门文章怎么调用等等,直接上代码,具体根据自己实际情况来修改使用,因为代码并不一定百分百适应全部主题要修改查询字段。本站也做了一个按月浏览的单页面,下附链接
wordpress获取一周热门文章排行
<?php function mostweek($where = '') { //获取最近七天的文章 $where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'"; return $where; } add_filter('posts_where', 'mostweek'); ?> <?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li> <?php endwhile; ?> <?php endif; ?>
wordpress获取一月热门文章排行
<?php function mostmonth($where = '') { //获取最近30天文章 $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'mostmonth'); ?> <?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li> <?php endwhile; ?> <?php endif; ?>
2021年10月3日更新
根据评论数获取热门
<h2>热门文章</h2> <ul id="popular-posts"> <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 6"); foreach ($result as $post) { setup_postdata($post); $postid = $post->ID; $title = $post->post_title; $commentcount = $post->comment_count; if ($commentcount != 0) { ?> <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"> <?php echo $title ?></a> {<?php echo $commentcount ?> 个评论}</li> <?php } } ?> </ul>
wordpress获取一周热门文章排行
<?php function mostweek($where = '') { //获取最近七天的文章 $where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'"; return $where; } add_filter('posts_where', 'mostweek'); ?> <?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li> <?php endwhile; ?> <?php endif; ?>
wordpress获取一月热门文章排行
<?php function mostmonth($where = '') { //获取最近30天文章 $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'mostmonth'); ?> <?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li> <?php endwhile; ?> <?php endif; ?>
按月浏览排行演示:https://www.izhailong.com/hot
龙哥 发表于 1年前 (2021-04-19),共2497字
版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:wordpress根据浏览次数获取本周或本月热门文章 || https://www.izhailong.com/384.html
本文由:版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:wordpress根据浏览次数获取本周或本月热门文章 || https://www.izhailong.com/384.html
暂无评论