Viewing 1 replies (of 1 total)
  • 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: https://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.