[resolved] [Plugin: Popular Posts] How To Crop Images To Specific Size (2 posts)

  1. globalspecialfx
    Posted 4 years ago #

    I have 3 featured posts on my pain page, and I'm trying to automatically display a custom-sized thumbnail of each image. I used the {php} function of popular posts, and my code looks like this:

    if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumb' ); }

    I registered the new thumbnail size in functions.php with the following code:

    if ( function_exists( 'add_theme_support' ) ) {
    	add_theme_support( 'post-thumbnails' );
            set_post_thumbnail_size( 150, 150 ); // default Post Thumbnail dimensions
    if ( function_exists( 'add_image_size' ) ) {
    	add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
    	add_image_size( 'homepage-thumb', 200, 137, true ); //(cropped)

    The problem is that THE SAME THUMBNAIL IS SHOWING UP FOR EVERY POST! WTF??? I even re-generated all of my thumnails, but I still have the same problem.

    I found a different php code, but it required the image source in order to crop, and there's no way that I can include each specific image source in the automatically-generated code, because Popular Posts won't recognize {imagesrc} if it's nested inside the {php} tag. Please help.

  2. globalspecialfx
    Posted 4 years ago #

    I finally found a work-around in the plugin's code... I actually changed the default thumbnail size to the thumbnail size I needed for the homepage posts (and set it to crop instead of re-sizing proportionally), then I used the following code found on the author's website:


    ...which displays the default image thumbnail for the post. This gives me the exact desired effect I was looking for. The only difference is that my default thumbnail size is now different, but I expect that if I need to use a 150x150 thumbnail anywhere, I will be able to manually include it with the additional size I created to back it up in functions.php, because I don't plan on running into another issue of seemingly having to use nested shortcode anytime in the near future...

Topic Closed

This topic has been closed to new replies.

About this Topic