Advertisement
Guest User

Untitled

a guest
Feb 17th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /*----------------------------------------------------------------------------------*/
  2. /* Popular Post in functions.php
  3. /*----------------------------------------------------------------------------------*/
  4. function getPostViews($postID){
  5. $count_key = 'post_views_count';
  6. $count = get_post_meta($postID, $count_key, true);
  7. if($count==''){
  8. delete_post_meta($postID, $count_key);
  9. add_post_meta($postID, $count_key, '0');
  10. return "0 View";
  11. }
  12. return $count.' Views';
  13. }
  14.  
  15. function setPostViews($postID) {
  16. $count_key = 'post_views_count';
  17. $count = get_post_meta($postID, $count_key, true);
  18. if($count==''){
  19. $count = 0;
  20. delete_post_meta($postID, $count_key);
  21. add_post_meta($postID, $count_key, '0');
  22. }else{
  23. $count++;
  24. update_post_meta($postID, $count_key, $count);
  25. }
  26. }
  27.  
  28. /*------------------------------------------------------------------------*/
  29. /* Set post views in single.php
  30. /*------------------------------------------------------------------------*/
  31. setPostViews(get_the_ID());
  32.  
  33. /*------------------------------------------------------------------------*/
  34. /* Loop in index.php
  35. /*------------------------------------------------------------------------*/
  36. <?php $newspopularpost = new WP_Query( array( 'category_name = news','meta_key= post_views_count', 'orderby= meta_value_num', 'order= DESC' ) );
  37. if ( $newspopularpost -> have_posts() ) : while ( have_posts() -> the_post); ?>
  38.  
  39. <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><h1><?php the_title(); ?></h1></a>
  40. <?php the_excerpt(); ?>
  41.  
  42. <?php endif; ?>
  43. <?php wp_reset_query(); ?>
  44. /* Wash, rinse, repeat for each of the 6 primary categories */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement