0

I have the query_post on my codes. This will display the popular post of all time. But I want to dispaly the popular post in past 24 hours. How do I do that?

<?php query_posts('orderby=comment_count&order=DESC&paged=' . get_query_var('paged'));?>

I have seen many answer here related to this topic, But not exactly this code. Following is my full code.

<?php
/*
Template Name: try
*/
?>
<?php get_header(); ?>
    <div id="content">
                 <div class="filter_bar"><div class="fb_title">Blog Archieves</div></div>
          <div id="content_inner">
        <?php if ( ! dynamic_sidebar( 'Alert' ) ) : ?>
            <!--Wigitized 'Alert' for the home page -->
        <?php endif ?>

         <div id="blog_wrapper">


 <?php query_posts('showposts=15&orderby=comment_count&order=DESC&paged=' . get_query_var('paged'));?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

          <ul class="lp_lists">
            <li class="lp_container">
                <div class="lp_left">
                    <?php if(has_post_thumbnail()) :?>
                    <div class="thumbnailimg">
                            <?php the_post_thumbnail(); ?>
                    </div>
                    <?php endif; ?>
                    <div class="lp_desc">
                     <?php the_excerpt(); ?>
                    </div>
                </div><!--lp left ends-->
                <div class="lp_right">
                    <div class="lp_title">
                       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </div>
                    <div class="lp_category">
                        <?php the_category(', ') ?>
                    </div>
                    <div class="lp_dates">
                       <?php echo get_the_date(); ?><span class="spacer">at</span><?php echo get_the_time(); ?>
                    </div>
                 <?php if(function_exists(kkLikeButton())){kkLikeButton();}?>

                </div><!--lp right ends-->
                <div style="clear: both;"></div>
            </li><!--lp container ends-->
            </ul>
            <div style="clear: both;"></div>
                <?php endwhile; else: ?>
           <div class="no-results">
            <p><strong><?php _e('There has been an error.'); ?></strong></p>
            <p><?php _e('We apologize for any inconvenience, please hit back on your browser or use the search form below.'); ?></p>
            <?php get_search_form(); /* outputs the default Wordpress search form */ ?>
        </div><!--noResults-->
        <?php endif; ?>
          </div>

        <div class="oldernewer">
            <p class="older"><?php next_posts_link('&laquo; Older Entries') ?></p>
            <p class="newer"><?php previous_posts_link('Newer Entries &raquo;') ?></p>
        </div><!--.oldernewer-->
             </div><!--content_inner ends-->
    </div><!--#content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
  • you mean the current day posts? – Rahil Wazir Nov 27 '13 at 21:26
  • yeah. the current day popular post. the popular post should be the popular post of the day form all the posts I have got, not only from the posts form today but from all the post. – diwas bhattarai Nov 27 '13 at 21:38
0

http://wordpress.org/plugins/wordpress-popular-posts/ use this plugin

you can use Time Range - list those posts of your blog that have been the most popular ones within a specific time range (eg. last 24 hours, last 7 days, last 30 days, etc.)!

go to plugins page just try i think you will satisfy

0

The answer by @Rahil is correct and the only reason it might not work with you is he has used date_query in his answer which works for WordPress version 3.7 and above, so if you are using a lower version it wont work for you. You can try the below code to get this done

Assumption is by 24 hours means for the very day

<?php
$args = array(
    'showposts' => 15,
    'orderby'   => 'comment_count',
    'order'     => 'DESC',
    'paged'     => get_query_var('paged'),
    'monthnum'  => date('m'),
    'day'       => date('d'),
    'year'      => date('Y')
);

   $loop = new WP_Query($args);
   if ($loop->have_posts()) :
       while ($loop->have_posts()) : $loop->the_post(); ?>
0

Please don't use query_posts. For clarification you can read here.

To show current day posts only, you can use below argument for your query:

Just replace these two lines in your file:

<?php query_posts('showposts=15&orderby=comment_count&order=DESC&paged=' . get_query_var('paged'));?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

With this:

<?php
 $_args = array(
     'showposts' => 15,
     'orderby' => 'comment_count',
     'order' => 'DESC',
     'paged' => get_query_var('paged'),
     'date_query' => array(
         array(
            'day' => date('d'),
        'monthnum' => date('M'),
        'year' => date('Y'),
         ),
      ),
     'meta_key' => 'kklike_value',
     'meta_value' => 'meta_value_num',
 );

    $loop = new WP_Query($_args);
    if ($loop->have_posts()) :
        while ($loop->have_posts()) : $loop->the_post(); ?>

Edited:

Ok you have to add these two more keys and values. See above for full code.

'meta_key' => 'kklike_value',
'meta_value' => 'meta_value_num',
  • the thing is I am new to wordpress. So you have to explain me where to put this code. Shall I just delete the query_posts line and replace with your code or what? – diwas bhattarai Nov 27 '13 at 21:40
  • @diwasbhattarai see my edited answer! – Rahil Wazir Nov 27 '13 at 21:50
  • you can see my page code. I have edited my question. – diwas bhattarai Nov 27 '13 at 21:51
  • I tested your code. It just show the most recent post. It doesnot work. I want to show the popular post from last 24 hours not recent post. – diwas bhattarai Nov 27 '13 at 22:04
  • Popular posts in which context? Popular post by comment count? or what? – Rahil Wazir Nov 27 '13 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.