【问题标题】:WordPress - show most read posts in 7 days, query by filterWordPress - 显示 7 天内阅读最多的帖子,按过滤器查询
【发布时间】:2013-07-01 10:51:24
【问题描述】:

我有 wordpress 插件,我有这个查询和过滤器:

<?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 ); ?>

我需要获取 7 天内阅读次数最多的帖子,但此查询仅显示最近 7 天的帖子,当我在过去 7 天内没有输入任何帖子时,插件将显示没有帖子 = 我必须写帖子。 .. 但我想让它始终显示 7 天内阅读次数最多的帖子...

非常感谢

【问题讨论】:

    标签: php arrays wordpress posts


    【解决方案1】:

    这里是插件WP Plugin: Top 10 posts and Views per post下载这个插件并编辑top10.php用这个替换函数show_pop_posts()

    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>";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 2016-05-13
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多