title: Creating a list of most popular posts of the past week - Wordpress
body: <p>I have created a widget for my Wordpress platform that displays the most popular posts of the week. However, there is an issue with it. It counts the most popular posts from <strong>Monday</strong>, not the past 7 days. For instance, this means that on Tuesday, it will only include posts from Tuesday and Monday.</p>
  
  <p>Here is my widget code:</p>
  
  <pre><code>&lt;?php class PopularWidget extends WP_Widget
  {
      function PopularWidget(){
          $widget_ops = array('description' =&gt; 'Displays Popular Posts');
          $control_ops = array('width' =&gt; 400, 'height' =&gt; 300);
          parent::WP_Widget(false,$name='ET Popular Widget',$widget_ops,$control_ops);
      }
  
    /* Displays the Widget in the front-end */
      function widget($args, $instance){
          extract($args);
          $title = apply_filters('widget_title', empty($instance['title']) ? 'Popular This Week' : $instance['title']);
          $postsNum = empty($instance['postsNum']) ? '' : $instance['postsNum'];
          $show_thisweek = isset($instance['thisweek']) ? (bool) $instance['thisweek'] : false;
  
          echo $before_widget;
  
          if ( $title )
          echo $before_title . $title . $after_title;
  
  ?&gt;
  &lt;?php
      $additional_query = $show_thisweek ? '&amp;year=' . date('Y') . '&amp;w=' . date('W') : '';
  
      query_posts( 'post_type=post&amp;posts_per_page='.$postsNum.'&amp;orderby=comment_count&amp;order=DESC' . $additional_query ); ?&gt;
          &lt;div class="widget-aligned"&gt;
          &lt;h3 class="box-title"&gt;Popular Articles&lt;/h3&gt;
          &lt;div class="blog-entry"&gt;
              &lt;ol&gt;
      &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
              &lt;li&gt;&lt;h4 class="title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h4&gt;&lt;/li&gt;
      &lt;?php endwhile; endif; wp_reset_query(); ?&gt;
              &lt;/ol&gt;
          &lt;/div&gt;
          &lt;/div&gt; &lt;!-- end widget-aligned --&gt;
          &lt;div style="clear:both;"&gt;&lt;/div&gt;
  &lt;?php
          echo $after_widget;
      }
  
    /*Saves the settings. */
      function update($new_instance, $old_instance){
          $instance = $old_instance;
          $instance['title'] = stripslashes($new_instance['title']);
          $instance['postsNum'] = stripslashes($new_instance['postsNum']);
          $instance['thisweek'] = 0;
          if ( isset($new_instance['thisweek']) ) $instance['thisweek'] = 1;
  
          return $instance;
      }
  
    /*Creates the form for the widget in the back-end. */
      function form($instance){
          //Defaults
          $instance = wp_parse_args( (array) $instance, array('title'=&gt;'Popular Posts', 'postsNum'=&gt;'','thisweek'=&gt;false) );
  
          $title = htmlspecialchars($instance['title']);
          $postsNum = htmlspecialchars($instance['postsNum']);
  
  
          # Title
          echo '&lt;p&gt;&lt;label for="' . $this-&gt;get_field_id('title') . '"&gt;' . 'Title:' . '&lt;/label&gt;&lt;input class="widefat" id="' . $this-&gt;get_field_id('title') . '" name="' . $this-&gt;get_field_name('title') . '" type="text" value="' . $title . '" /&gt;&lt;/p&gt;';
          # Number of posts
          echo '&lt;p&gt;&lt;label for="' . $this-&gt;get_field_id('postsNum') . '"&gt;' . 'Number of posts:' . '&lt;/label&gt;&lt;input class="widefat" id="' . $this-&gt;get_field_id('postsNum') . '" name="' . $this-&gt;get_field_name('postsNum') . '" type="text" value="' . $postsNum . '" /&gt;&lt;/p&gt;';  ?&gt;
          &lt;input class="checkbox" type="checkbox" &lt;?php checked($instance['thisweek'], 1) ?&gt; id="&lt;?php echo $this-&gt;get_field_id('thisweek'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('thisweek'); ?&gt;" /&gt;
          &lt;label for="&lt;?php echo $this-&gt;get_field_id('thisweek'); ?&gt;"&gt;&lt;?php esc_html_e('Popular this week','Aggregate'); ?&gt;&lt;/label&gt;
          &lt;?php
      }
  
  }// end AboutMeWidget class
  
  function PopularWidgetInit() {
    register_widget('PopularWidget');
  }
  
  add_action('widgets_init', 'PopularWidgetInit');
  
  ?&gt;
  </code></pre>
  
  <p>How can I change this script so that it will count the past 7 days rather than posts from last Monday?</p>