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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题