WordPress.org

Forums

[resolved] display thumbnail of most popular post (5 posts)

  1. justinblayney
    Member
    Posted 2 years ago #

    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();
    ?>
  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Are you using a plugin that stores post views in your database?

  3. justinblayney
    Member
    Posted 2 years ago #

    that is my first code block... not a plugin, just a function

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    But are you using a plugin that stores post views in your database? This is not part of core WordPress.

  5. justinblayney
    Member
    Posted 2 years ago #

    hi esmi,

    sorry you are not understating... everything works fine except displaying the image...

    i figured it out

Topic Closed

This topic has been closed to new replies.

About this Topic