WordPress.org

Ready to get started?Download WordPress

Forums

Last Viewed Posts
Adding thumbnail image (2 posts)

  1. dwilson716
    Member
    Posted 11 months ago #

    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/

  2. joshuaiz
    Member
    Posted 8 months ago #

    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/

    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!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.