Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------------*/
- /* Popular Post in functions.php
- /*----------------------------------------------------------------------------------*/
- function getPostViews($postID){
- $count_key = 'post_views_count';
- $count = get_post_meta($postID, $count_key, true);
- if($count==''){
- delete_post_meta($postID, $count_key);
- add_post_meta($postID, $count_key, '0');
- return "0 View";
- }
- return $count.' Views';
- }
- function setPostViews($postID) {
- $count_key = 'post_views_count';
- $count = get_post_meta($postID, $count_key, true);
- if($count==''){
- $count = 0;
- delete_post_meta($postID, $count_key);
- add_post_meta($postID, $count_key, '0');
- }else{
- $count++;
- update_post_meta($postID, $count_key, $count);
- }
- }
- /*------------------------------------------------------------------------*/
- /* Set post views in single.php
- /*------------------------------------------------------------------------*/
- setPostViews(get_the_ID());
- /*------------------------------------------------------------------------*/
- /* Loop in index.php
- /*------------------------------------------------------------------------*/
- <?php $newspopularpost = new WP_Query( array( 'category_name = news','meta_key= post_views_count', 'orderby= meta_value_num', 'order= DESC' ) );
- if ( $newspopularpost -> have_posts() ) : while ( have_posts() -> the_post); ?>
- <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><h1><?php the_title(); ?></h1></a>
- <?php the_excerpt(); ?>
- <?php endif; ?>
- <?php wp_reset_query(); ?>
- /* Wash, rinse, repeat for each of the 6 primary categories */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement