Title: Thumbnail in Widget
Last modified: August 21, 2016

---

# Thumbnail in Widget

 *  Resolved [Arthy1](https://wordpress.org/support/users/arthy1/)
 * (@arthy1)
 * [12 years ago](https://wordpress.org/support/topic/thumbnail-in-widget/)
 * Hi,
 * I would like to know if it is possible to add a thumbnail image in the widget
   of WP-postViews
 * Thanks for your answer,
 * Arthy
 * [https://wordpress.org/plugins/wp-postviews/](https://wordpress.org/plugins/wp-postviews/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [12 years ago](https://wordpress.org/support/topic/thumbnail-in-widget/#post-4854702)
 * Sorry that is not possible because the thumbnail is not retrieve from the query
   to the DB.
 *  [Angel Costa](https://wordpress.org/support/users/angelcosta/)
 * (@angelcosta)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/thumbnail-in-widget/#post-4854945)
 * You can do it by editing the plugin code. Look for wp-postviews/wp-postviews.
   php and search for the function you’ll be using in your widget.
 * In my case I am using most viewed pages/post. So I scrolled down and find:
 * ### Function: Display Most Viewed Page/Post
 * Then you look for the last $temp line (within that function):
 * `$temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $
   post), $temp);`
 * And you add this right below:
    `$temp = str_replace("%POST_IMG%", get_the_post_thumbnail(),
   $temp);`
 * Now, get back to the template and set it using %POST_IMG% wherever you want the
   image to appear:
 * `<li>%POST_IMG%<br /><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</
   a></li>`
 * Remember to have a fallback image: [http://justintadlock.com/archives/2012/07/05/how-to-define-a-default-post-thumbnail](http://justintadlock.com/archives/2012/07/05/how-to-define-a-default-post-thumbnail)
 * This is actually pretty simple and could come with the plugin.
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/thumbnail-in-widget/#post-4854947)
 * Is not that straightforward with the current code base. By using get_the_post_thumbnail(),
   you will incur 1 query for every post make. So if you are showing Top 20 Most
   Viewed Post, it will have additional 20 queries.
 * A better way of doing this will be to use query_post() to replace the existing
   widget sql query. That is on my to-do list.
 *  [delatdecatsini](https://wordpress.org/support/users/delatdecatsini/)
 * (@delatdecatsini)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/thumbnail-in-widget/#post-4854983)
 * Do you finish? And how to replace the existing widget sql query with query_post()?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Thumbnail in Widget’ is closed to new replies.

 * ![](https://ps.w.org/wp-postviews/assets/icon.svg?rev=978002)
 * [WP-PostViews](https://wordpress.org/plugins/wp-postviews/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-postviews/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-postviews/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-postviews/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-postviews/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-postviews/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [delatdecatsini](https://wordpress.org/support/users/delatdecatsini/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/thumbnail-in-widget/#post-4854983)
 * Status: resolved