How to make images appear in WP Favourite Posts Plugin & Widget

Bish
Bash
Boshanka
Let's get it done!

0 Shares

Just a quick one for today. I’ve been working with the WP Favorite posts plugin and whilst it’s a fantastic plugin to quickly allow your users to build up a notebook of their favorite articles from your website or blog, it was missing the ability to include images either on the notebook page or the most Favorited widget.

To make thumbnails appear, on the widget, you’ll need to first set up a new thumbnail size image in your functions.php file, I created the image size ’90×90′.

Open up functions.php and add the following line:

1
add_image_size( '90x90', 150, 150);

Next up, open up wp-favorite-posts.php located in the folder for the WP Favorite Posts Plugin and scroll down to around line 216. Locate the following code:

1
2
3
4
5
6
7
function wpfp_list_most_favorited($limit=5) {
global $wpdb;
$query = "SELECT post_id, meta_value, post_status FROM $wpdb->postmeta";
$query .= " LEFT JOIN $wpdb->posts ON post_id=$wpdb->posts.ID";
$query .= " WHERE post_status='publish' AND meta_key='".WPFP_META_KEY."' AND meta_value > 0 ORDER BY ROUND(meta_value) DESC LIMIT 0, $limit";
$results = $wpdb->get_results($query);
if ($results) {

Just below it, alter the code to look like what I have below:

1
2
3
4
5
6
7
8
9
10
11
12
13
    echo "<ul>";
        foreach ($results as $o):
            $p = get_post($o->post_id);
            echo "<li class='most-fave-posts'>";
            echo "<a href='".get_permalink($o->post_id)."' title='". $p->post_title ."'>";
            echo get_the_post_thumbnail( $o->post_id,'90x90' );
            echo "<span>" .$p->post_title. " ($o->meta_value)";
            echo "</span>";
           
                    echo "</a>";
   
        endforeach;
        echo "</ul>";

The above will make the widget display images for you, but you can reuse the same code inside ‘wpfp-page-template.php’ to get it working on your notebook page too.

Happy Coding!

0 0 votes
Article Rating
Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Hasan
10 years ago

Don’t code

Alan
Alan
7 years ago

I have done it and it is not working. Are you referring to the functions.php of the template? I’m using Hueman and added the add_image_size( ’90×90′, 150, 150); to the functions.php, but nothing is showing up. Can you please help?

Martin Schulz
Martin Schulz
2 years ago

Its doesn’t work

Bish
Bash
Boshanka
Let's get it done!

Based in London, Working Everywhere

I’m a Freelance Web Designer and WordPress developer, I’m based in London but work with client’s in the UK and all over the world.

Creative Web Design & WordPress Development Services