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 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决