Advertisement
salmancreation

সর্বাধিক পঠিক সংবাদ Wordpress

Jan 26th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. copy this code and paste to function.php
  2. -----------------------^---------------------
  3. <?php
  4.  
  5. /* Visit Counter For WordPress by salmancreation.com */
  6. function getPostViews($postID){
  7. $count_key = 'post_views_count';
  8. $count = get_post_meta($postID, $count_key, true);
  9. if($count==''){
  10. delete_post_meta($postID, $count_key);
  11. add_post_meta($postID, $count_key, '0');
  12. return "0 বার";
  13. }
  14. return $count.' বার';
  15. }
  16. function setPostViews($postID) {
  17. $count_key = 'post_views_count';
  18. $count = get_post_meta($postID, $count_key, true);
  19. if($count==''){
  20. $count = 0;
  21. delete_post_meta($postID, $count_key);
  22. add_post_meta($postID, $count_key, '0');
  23. }else{
  24. $count++;
  25. update_post_meta($postID, $count_key, $count);
  26. }
  27. }
  28.  
  29.  
  30. ?> 
  31.  
  32. ----function.php-----------------------code end----------------------------------->
  33.  
  34. ======================================================================
  35. copy this code it and paste a in your index.php where you want  |>
  36. ======================================================================
  37.  
  38.     <span class="catagoryHeading">সর্বাধিক পঠিক সংবাদ</span>
  39.         <ul class="catagory">
  40.             <?php
  41.             $popularpost = new WP_Query( array( 'posts_per_page' => 5, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC'  ) );
  42.             while ( $popularpost->have_posts() ) : $popularpost->the_post();?>
  43.             <li>
  44.             <a href="<?php the_permalink() ?>">"<?php the_title();?></a>
  45.             </li>
  46.             <?php endwhile; ?>
  47.             <?php wp_reset_query(); ?>
  48.         </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement