Hi JRadagast,
Try this:
- Open wordpress-popular-posts.php using a text editor (or edit it directly from Plugins > Editor > WordPress Popular Posts).
- Around line 1199 you’ll find the relevant code block that builds the thumbnail. Replace it completely with the following:
// POST THUMBNAIL
if ($instance['thumbnail']['active'] && $this->thumb) {
$tbWidth = $instance['thumbnail']['width'];
$tbHeight = $instance['thumbnail']['height'];
$thumb = "<a href=\"". $permalink ."\" title=\"{$title}\" target=\"".$this->user_ops['tools']['link']['target']."\">";
if (function_exists('get_the_post_thumbnail') && has_post_thumbnail( $p->id )) { // check if the user has selected a post thumbnail
$thumb .= get_the_post_thumbnail($p->id, array($tbWidth, $tbHeight), array('class' => 'wpp-thumbnail', 'alt' => esc_attr($title), 'title' => esc_attr($title)) );
} else { // get first image from post
$thumb .= $this->get_img( $p->id, array($tbWidth, $tbHeight), 'first_image' );
}
$thumb .= "</a>";
}
- Save changes.
I have not tested this, but it should work.
Keep in mind that this is a modification (hack) and will get overwritten once a new version of the plugin is available.
Thanks man, it worked.
I’ll save this change somewhere just to remember.
Great plugin btw.
Héctor, is this code block around line 1199 yet? Thanks.
Hi Fernando,
Nope, the plugin has changed a lot since then. Now you’d need to make this change on the __render_popular_post()
function, to be more precise you’ll have to replace one variable (around line 1687):
$thumb = $this->_get_thumb($p, $instance);
… with the hack posted above. Also, $this->user_ops
is now $this->user_settings
.
Can you add this as a new feature in the next update, because why not?
I’ll think about it, but no promises.
Hello. I can’t seem to make this change work. I’m just supposed to delete this line
$thumb = $this->_get_thumb($p, $instance);
and add this code, right?
if ($instance['thumbnail']['active'] && $this->thumb) {
$tbWidth = $instance['thumbnail']['width'];
$tbHeight = $instance['thumbnail']['height'];
$thumb = "<a href=\"". $permalink ."\" title=\"{$title}\" target=\"".$this->user_settings['tools']['link']['target']."\">";
if (function_exists('get_the_post_thumbnail') && has_post_thumbnail( $p->id )) { // check if the user has selected a post thumbnail
$thumb .= get_the_post_thumbnail($p->id, array($tbWidth, $tbHeight), array('class' => 'wpp-thumbnail', 'alt' => esc_attr($title), 'title' => esc_attr($title)) );
} else { // get first image from post
$thumb .= $this->get_img( $p->id, array($tbWidth, $tbHeight), 'first_image' );
}
$thumb .= "</a>";
}
I really don’t know what I’m doing wrong… But everytime I change it, the thumbnail disappears completely – no featured image, no first image from the post, nothing. Help?
Ah, sorry about that. There are additional changes to be made I didn’t notice before. Here’s the updated code (didn’t test it though, so let me know how it goes):
if ( $instance['thumbnail']['active'] && $this->thumbnailing ) {
$tbWidth = $instance['thumbnail']['width'];
$tbHeight = $instance['thumbnail']['height'];
$thumb = "<a href=\"". $permalink ."\" title=\"{$title}\" target=\"".$this->user_settings['tools']['link']['target']."\">";
if (function_exists('get_the_post_thumbnail') && has_post_thumbnail( $p->id )) { // check if the user has selected a post thumbnail
$thumb .= get_the_post_thumbnail($p->id, array($tbWidth, $tbHeight), array('class' => 'wpp-thumbnail', 'alt' => esc_attr($title), 'title' => esc_attr($title)) );
} else { // get first image from post
$thumb .= $this->__get_img( null, $p->id, null, array($tbWidth, $tbHeight), 'first_image', $title );
}
$thumb .= "</a>";
}
Now it works perfectly! Thank you!