dongqun9403 2013-07-01 10:51
浏览 28
已采纳

WordPress - 在7天内显示大多数阅读帖子,按过滤查询

I have wordpress plugin and there I have this query and filter:

<?php
  function filter_where($where = '') {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
?>

<?php query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC&ignore_sticky_posts=1&posts_per_page='. $numposts ); ?>

I need to get posts that are most read in 7 days, but this query only shows posts last 7 days, and when I do not type any post in lasts 7 days, plugin will show no posts = I must write posts... But I want to make that will show always most read posts in 7 days...

Thank you very much

  • 写回答

1条回答 默认 最新

  • dqm7854 2013-07-01 12:09
    关注

    Here is the plugin WP Plugin: Top 10 posts and Views per post download this plugin and edit top10.php replace the function show_pop_posts() with this one

    function show_pop_posts() {
        global $wpdb, $siteurl, $tableposts, $id;
        $results = $wpdb->get_results("select postnumber, cntaccess from mostAccessed ORDER BY cntaccess DESC LIMIT 7");
        echo "<ul>";
        if ($results) {
            foreach ($results as $result) {
                echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a> ('.$result->cntaccess.')</li>';
            }
        }
        echo "</ul>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看