WordPress.org

Ready to get started?Download WordPress

Forums

Popular Post in the last 7 Days (3 posts)

  1. RubenRTK
    Member
    Posted 3 years ago #

    Hey guys I'm having a problem with the following code, On my website at http://www.tek-bull.com I have a popular post sidebar, but the only problem is that since I have very old articles, those are the ones that come up. I'm trying to change the code so it only displays the most popular post in the last 7 days. Here is the code that I need to change this on. Any Help?

    "<?php
    query_posts('meta_key=post-counter&order=DESC&orderby=meta_value_num&
    showposts=5');

    if (have_posts()) :
    $i = 1;
    while ( have_posts() ) : the_post()
    ?>"

  2. Tara
    Member
    Posted 3 years ago #

    try this (not tested):

    <?php function filter_where($where = '') { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); $popular = new WP_Query('post_type=guide&orderby=comment_count&posts_per_page=4'); ?><?php while ($popular->have_posts()) : $popular->the_post(); ?><!-- DO STUFF --><?php endwhile; wp_reset_query(); ?>

  3. RubenRTK
    Member
    Posted 3 years ago #

    It didn't parsed correctly, the code caused the side bar to crash completely with a fatal error, do you know where I would have to put the code?. Here is the full code in the "section"

    <div class="section">
    <p class="splitter minor"><span>Top 5 Popular Articles</span></p>

      <?php
      query_posts('meta_key=post-counter&order=DESC&orderby=meta_value_num&showposts=5');
      if (have_posts()) :
      $i = 1;
      while ( have_posts() ) : the_post()
      ?>

      <li class="post top5 clearfix">
      " class="post_link">
      <span class="top5_number"><?php echo $i;?></span>
      <span class="post_image_frame"><img class="thumb" src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php echo urlencode(tj_get_image($post->ID, 'full')); ?>&h=60&w=100&zc=0" alt="<?php the_title(); ?>" /></span>
      <strong class="entry-title"><?php the_title();?>

      <?php $i++; endwhile; endif; wp_reset_query();?>

    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic