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

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

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

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!

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

  1. Hasan  October 29, 2013 at 12:22 pm

    Don’t code

  2. Alan  February 8, 2017 at 8:13 am

    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?

Leave a Reply

Enjoyed this article?

If you enjoyed this article please rate & share.

You Might Also Like