WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] display thumbnail of most popular post

[Resolved] display thumbnail of most popular post

  • justinblayney
    Member

    @justinblayney

    hello, I would like to display the most popular post’s thumbnail image outside of the loop. I found a fucntion which fetches the most popular post and will display the_permalink and the the_title… but I cant integrate it with get_the_post_thumbnail

    please help me display the thumbnail

    this code fetches the popular post

    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);
        }
    
    }

    this is my display code

    <?php
    	query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC');
    	if (have_posts()) : while (have_posts()) : the_post();
    echo the_permalink();
    	?>
         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" ><?php echo get_the_post_thumbnail($post->ID, 'single-post-thumbnail'); ?></a>
    
    	<?php
    	endwhile; endif;
    	wp_reset_query();
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] display thumbnail of most popular post’ is closed to new replies.