Title: Adding thumbnail image
Last modified: August 21, 2016

---

# Adding thumbnail image

 *  [dwilson716](https://wordpress.org/support/users/dwilson716/)
 * (@dwilson716)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/adding-thumbnail-image/)
 * I read the previous issue with getting the thumbnail image to display but I cant
   seem to get it to work.
 * I wish to display the post title with the featured image displayed underneath?
   Please can someone share the code so I can add this in?
 * Many thanks
 * Dan
 * [http://wordpress.org/plugins/last-viewed-posts/](http://wordpress.org/plugins/last-viewed-posts/)

Viewing 1 replies (of 1 total)

 *  [joshuaiz](https://wordpress.org/support/users/joshuaiz/)
 * (@joshuaiz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-thumbnail-image/#post-4099193)
 * After doing some serious sleuthing, I finally got this plugin to show the post
   thumbnail using the following.
 * In last_viewed_posts.php, line 88, change to this:
 *     ```
       function zg_recently_viewed() { // Output
       	echo '<ul class="viewed_posts">';
       	if (isset($_COOKIE["WP-LastViewedPosts"])) {
       		//echo "Cookie was set.<br/>";  // For bugfixing - uncomment to see if cookie was set
       		//echo $_COOKIE["WP-LastViewedPosts"]; // For bugfixing (cookie content)
       		$zg_post_IDs = unserialize(preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", stripslashes($_COOKIE["WP-LastViewedPosts"]))); // Read serialized array from cooke and unserialize it
       		foreach ($zg_post_IDs as $value) { // Do output as long there are posts
       			global $wpdb;
       			$zg_get_title = $wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE ID = '$value+0' AND ID IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = '5' ) LIMIT 1");
       			$thumb = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent = '$value+0' and post_type = 'attachment'");
       			$thumbnail = wp_get_attachment_thumb_url($thumb);
       			foreach($zg_get_title as $zg_title_out) {
       				echo "<li><a href=\"". get_permalink($value+0) . "\" title=\"". $zg_title_out->post_title . "\"><img src='" .$thumbnail. "'alt='' />" . $zg_title_out->post_title . "</a></li>\n"; // Output link and title
       			}
       		}
       	} else {
       		//echo "No cookie found.";  // For bugfixing - uncomment to see if cookie was not set
       	}
       	echo '</ul>';
       }
       ```
   
 * Notice the $thumb section. Also in the first $zg_get_title SQL query, I added
   a bit to get posts only from a particular category but you may not need that.
 * Also I am not a mysql master by any means so the two SQL queries could probably
   be combined into one.
 * You can see this in action here: [http://vizualrecords.com/catalog/eps/viz014/](http://vizualrecords.com/catalog/eps/viz014/)
 * Note that on that page I have done a bit of styling so add html to the function
   above (and css) as necessary. But it works!

Viewing 1 replies (of 1 total)

The topic ‘Adding thumbnail image’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/last-viewed-posts.svg)
 * [Last Viewed Posts by WPBeginner](https://wordpress.org/plugins/last-viewed-posts/)
 * [Support Threads](https://wordpress.org/support/plugin/last-viewed-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/last-viewed-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/last-viewed-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/last-viewed-posts/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [joshuaiz](https://wordpress.org/support/users/joshuaiz/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/adding-thumbnail-image/#post-4099193)
 * Status: not resolved