• By default, WordPress Popular Posts will attempt to generate a thumbnail from the first image attached to your posts. However, you can also select a custom thumbnail by enabling The Post Thumbnail functionality on your blog. To do this, simply add this line of code to your theme’s functions.php file:

    // Enable post thumbnails
    add_theme_support(‘post-thumbnails’);

    Once you’re done with that, go to your WordPress Admin interface and you should see a nex bow called Post Thumbnail (renamed “Featured Image” on WordPress 3.0) under the Add New Post / Edit Post screens. Pick the image of your choice, click on Use as thumbnail (changed to “Use as featured image” on WordPress 3.0) and save changes.

    Now WordPress Popular Posts will use your selected images as thumbnails!

Viewing 8 replies - 16 through 23 (of 23 total)
  • Thread Starter Héctor Cabrera

    (@ikki24)

    Thanks for the link, patung.

    Since I don’t have MU installed, you’ll have to do the testing for me. Please open wordpress-popular-posts.php using an editor such as Windows’ Notepad or Adobe Dreamweaver, and change this (line 706):

    $img = $this->get_img($wppost->ID);
    if ( ($img && !empty($img)) ) {
        $thumb = "<a href=\"".get_permalink($wppost->ID)."\" class=\"wppgen\" title=\"". $title_attr ."\"><img src=\"". $this->pluginDir . "/scripts/timthumb.php?src=". $img[1] ."&h=".$tbHeight."&w=".$tbWidth."&zc=1\" alt=\"".$title_attr."\" border=\"0\" class=\"wpp-thumbnail\" width=\"".$tbWidth."\" height=\"".$tbHeight."\" "."/></a>";
    }

    … into this:

    $img = $this->get_img($wppost->ID);
    if ( ($img && !empty($img)) ) {
    	global $blog_id;
        if (isset($blog_id) && $blog_id > 0) {
            $imageParts = explode('/files/', $img[1]);
            if (isset($imageParts[1])) {
                $thumb = "<a href=\"".get_permalink($wppost->ID)."\" class=\"wppgen\" title=\"". $title_attr ."\"><img src=\"". $this->pluginDir . "/scripts/timthumb.php?src=". "/blogs.dir/" . $blog_id . "/files/" . $imageParts[1] ."&h=".$tbHeight."&w=".$tbWidth."&zc=1\" alt=\"".$title_attr."\" border=\"0\" class=\"wpp-thumbnail\" width=\"".$tbWidth."\" height=\"".$tbHeight."\" "."/></a>";
            }
        } else {
        	$thumb = "<a href=\"".get_permalink($wppost->ID)."\" class=\"wppgen\" title=\"". $title_attr ."\"><img src=\"". $this->pluginDir . "/scripts/timthumb.php?src=". $img[1] ."&h=".$tbHeight."&w=".$tbWidth."&zc=1\" alt=\"".$title_attr."\" border=\"0\" class=\"wpp-thumbnail\" width=\"".$tbWidth."\" height=\"".$tbHeight."\" "."/></a>";
        }
    }

    Let me know the results, ok?

    Brilliant! Works on domain mapped blogs too!

    Not sure if I’m doing something wrong here but on mainblog, blogid ‘1’, I can’t seem to get the post thumbnails generated, whereas as above your fix worked a charm for the sub-blogs. I just checked in the cache folder and there’s definitely nothing in there from today, when I tried out the widget for the mainblog; there are a lot of other images in there though from the sub-blogs.

    Hey Ikki24,

    is there a way the plugin can use YAPB generated thumbs? Like a 3rd option (besides usergenerated and wppgenerated)?

    On YAPB sites, the plugin does only show thumbs if the images are again uploaded/attached to the post (using the WP admin media uploader), something that already has been done by YAPB, so double work and double diskspace..
    If it can just use the Yapb cache?

    Cheers, Bike

    karimun

    (@karimun)

    Your script passes a truncated image name to timthumb.php if the name contains spaces (Should be the preg_match part).

    Here the changes I did in wordpress-popular-posts.php to make it work:

    Change line 795

    $img = wp_get_attachment_image($first_attachment->ID);
    preg_match('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'\s>]*)/i', $img, $imgm);

    into this
    $img = wp_get_attachment_image_src($first_attachment->ID);

    Change line 800
    return $imgm;
    into this
    return $img[0];

    And finally the path related code:

    In line 708 change
    timthumb.php?src=". $img[1]
    into this
    timthumb.php?src=". $img

    Thanks for your plugin.

    Found a way to use “Category designated thumbnails” with this plugin .
    Lets say you want to use a specific category thumbnail for a post instead of “no_thumb.jpg”, heres what you have to do :

    1. create a sub folder in the root of your wp installation (in this example the folder is “img” )

    2. name the images the same as the category name (if the category name is “30 Rock”, use “30 Rock.jpg”

    3. if you wanna use the category thumbnail somewhere else in the site use this code
    <img src="<?php echo get_option('home'); ?>/img/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" width="120" height="120" alt="<?php the_title_attribute(); ?>" /></a> <?php }

    4. if you want to use the category thumbnail instead of no_thumb.jpg with this specific plugin edit “wordpress-popular-posts.php” ; look for this line

    // default image
    $thumb = "<a href=\"".get_permalink($wppost->ID)."\" class=\"wppnothumb\" title=\"". $title_attr ."\"><img src=\"". $this->pluginDir . "/no_thumb.jpg\" alt=\"".$title_attr."\" border=\"0\" class=\"wpp-thumbnail\" width=\"".$tbWidth."\" height=\"".$tbHeight."\" "."/></a>";

    and replace it with this

    // default image
    $category = get_the_category($wppost->ID) ;
    $thumb = "<a href=\"".get_permalink($wppost->ID)."\" class=\"wppnothumb\" title=\"". $title_attr ."\"><img src=\"". get_option('home') ."/img/". $category[0]->cat_name .".jpg\" alt=\"".$title_attr."\" border=\"0\" class=\"wpp-thumbnail\" width=\"".$tbWidth."\" height=\"".$tbHeight."\" "."/></a>";

    5. if all went well, when a post does not have a ‘featured image’ of a thumbnail cannot be generated, it will show the category picture instead

    ** if a post is in more the one category it will show the first one; there is a way to make this work better just check this https://new2wp.com/rookie/2-5-ways-to-show-category-thumbnails/

    Hope this helps… i would really like to see this integrated in the widget somehow

    If I enable the Post Thumbnail feature what happens with the old post where I did no specified a featured image yet? The plugin keeps generating a thumbnail for them?

    Thanks for your time

    Will be great if the next version comes with a customizable option to clean cache periodically.

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Using the Post Thumbnail Feature with WordPress Popular Posts’ is closed to new replies.