Advertisement
firoze

Display Most Popular Posts In the Last 30 Days Without plugi

Jun 22nd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // Display Your Most Popular Posts In the Last 30 Days Without a Plugin
  2.  
  3. <ul>
  4. <h2><?php echo('Most Popular Posts');?></h2>
  5. <?php
  6. function filter_where($where = '') {
  7. //posts in the last 30 days
  8. $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
  9. return $where;
  10. }
  11. add_filter('posts_where', 'filter_where');
  12.  
  13. query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC');
  14.  
  15. while (have_posts()): the_post(); ?>
  16.  
  17. <li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a>
  18. </li>
  19.  
  20. <?php
  21. endwhile;
  22. wp_reset_query();
  23. ?>
  24. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement