• Resolved Viktor Nagornyy

    (@viktorix)


    Hi, question and possible issue.

    1. It seems that plugin pulls thumbnail for the post that is set inside Media page. BUT, if I set featured thumbnail in the functions.php file:

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 244, 168, true );

    Top 10 plugin ignores it, and still pulls 150×150 thumbnail. Might be a bug?

    2. How can I force Top 10 plugin to use custom field option for thumbnail? It keeps using featured thumbnail for the post that is incorrectly sized, even if I have custom field set in the Settings of the plugin.

    Thanks.

    https://ww.wp.xz.cn/plugins/top-10/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ajay

    (@ajay)

    Hi, the plugin pulls a featured image as the first option and only when this isn’t available does it look to the custom field.

    What are the settings for the thumbnail size in the Settings page for Top 10?

    What is the setting you have for thumbnail in Settings > Media?

    This is the portion of code that pulls the image. It checks if there is a thumbnail image and if this image is below the thumbnail width or height specified in the Top 10 settings page then it pulls out the full image.

    $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) );
    
    if ( ($postimage[1] < $thumb_width) || ($postimage[2] < $thumb_height) ) $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) , 'full' );
    $postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb );
    $output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';
    Thread Starter Viktor Nagornyy

    (@viktorix)

    Thanks, I will look into modifying that bit.
    Maybe adding a simple check for empty custom field input would be a good option, or checkbox to manually force it to use that image.

    I think the timthumb feature could be easily replaced with WP’s built-in image generation. We specify our image size and you can simply use those values inside:
    add_image_size( $name, $width, $height, $crop );

    And for any old images, users could use a plugin to force regenerate all images. Just a thought, since its better then timthumb.

    Plugin Author Ajay

    (@ajay)

    I agree. It’s one of the main things I plan to add into the plugin to remove the need for timthumb.

    Thread Starter Viktor Nagornyy

    (@viktorix)

    I was able to figure this out rather easily. I simply added new image size called “popular-img” and changed “full”. That did the trick of pulling new image size as I wanted it.

    $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID), 'popular-img' );
    
    if ( ($postimage[1] < $thumb_width) || ($postimage[2] < $thumb_height) ) $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) , 'popular-img' );
    $postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb );
    $output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';

    For anyone that’s interested in modifying it. You just need to update code above inside plugin’s file, and also add this line to create image size inside functions.php.

    add_image_size( 'popular-img', 200, 100, true );
    200 is width, 100 is height, true is crop.

    Note, this only applies to new images uploaded after you add above line. To apply this to old images, you need to use a plugin to force generate all images.

    Plugin Author Ajay

    (@ajay)

    Viktor,

    Thanks for the code. I’ll use this in the plugin and also make the add_image_size more dynamic and related to the image sizes in the Top 10 settings page.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘possible issue with thumbnail’ is closed to new replies.