WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[Plugin: WordPress Popular Posts] User Generated Thumbnails incorrect size (11 posts)

  1. purrdesign
    Member
    Posted 3 years ago #

    Trying to display popular posts pulling from the featured image I have set for each post. I have the thumbnails function enabled in my functions.php and it is set to hard crop thumbnail images to a square size. However, wpp seems to pull the Medium size image, which is not square, and then shrinks it down to the width I have set in the widget. So instead of having a row of nice square images, I have a row of images all the same width, but varying heights depending on the height of the original image.

    I do not want to use the timthumb script, but I cannot seem to get the usergenerated thumbnails to pull correctly from the hard cropped featured image.

  2. miickel
    Member
    Posted 3 years ago #

    We are experiencing the same issue at PixelTango. Take a look at this screen-shot, where the bottom right thumbnail is not working properly.

    Here's the code we use to output the images:
    wpp_get_mostpopular('limit=12&range=monthly&order_by=views&pages=0&thumbnail_selection=usergenerated&thumbnail_width=115&thumbnail_height=115&header_start="<h5><span>"&header_end="</span></h5>"&stats_comments=0&stats_views=0&do_pattern=1&pattern_form="{image}"');

    Any help or suggestions would be appreciated.

  3. leehalliday
    Member
    Posted 3 years ago #

    Yeah I have the same issue it seems that if you leave the widget to get the images by itself them the default image show up. But if you use the set images tab then the images show up but there sizes are all wrong. Can there be a fix for this please or at least a work around.

  4. miickel
    Member
    Posted 3 years ago #

    Here's what we did over at PixelTango.

    In functions.php:

    function popularPosts($num) {
        global $wpdb;
    	$mpQuery = "SELECT $wpdb->posts.ID, $wpdb->posts.post_name, $wpdb->posts.post_title, SUM(pageviews) AS pageviews FROM $wpdb->posts LEFT JOIN wp_popularpostsdatacache ON $wpdb->posts.ID = wp_popularpostsdatacache.id WHERE (day >= '" .gmdate("Y-m-d"). "' - INTERVAL 30 DAY) GROUP BY id ORDER BY pageviews DESC LIMIT " . $num . "";
    	$mostpopular = $wpdb->get_results($mpQuery);
        return $mostpopular;
    }

    And in our theme we use this with a regular wordpress loop like so:

    <ul class="sq-list">
        <?php $popular = popularPosts(16); foreach ($popular as $post) : setup_postdata($post); ?>
            <li><a title="<?php the_title(); ?>" href="<?php echo get_permalink($post->id); ?>"><?php the_post_thumbnail( 'post-tn-square', array( 'alt' => the_title( '', false, '' ), 'title' => the_title( '', false, '' ) ) ); ?></a></li>
        <?php endforeach; ?>
    </ul>

    Please note: I am in no way a good PHP-developer, so use this code with caution lol... Hopefully this is useful for someone!

  5. purrdesign
    Member
    Posted 3 years ago #

    Thanks Miickel! That code worked beautifully. :)

  6. purrdesign
    Member
    Posted 3 years ago #

    Maybe I spoke too soon. Popular posts display perfectly, but the permalinks are not working (they're trying to link to the 1970 version of the posts).

    Any ideas?

  7. purrdesign
    Member
    Posted 3 years ago #

    Got it.

    To fix this problem, and have this plugin pull the featured image you have selected for a post, edit the wordpress-popular-posts.php file. On line 703 you'll see the output for the user-selected thumbnails. Change:

    array($tbWidth)

    to

    'thumbnail'

    (or replace thumbnail with whatever the name of the featured image size you want to use.)

  8. leehalliday
    Member
    Posted 3 years ago #

    @ Purrdesign,

    I am finding your running commenter very interesting, has it all gone well now? Just a few question about your fix:

    - Does your latest fix still require all the code provided by 'miickel'?
    - When you say replace 'array($tbWidth)' with 'thumbnail' do you literal mean replace it or just '$tbWidth'? also do you need to use the quote marks around thumbnail?

    Cheers hope to hear form you.

  9. purrdesign
    Member
    Posted 3 years ago #

    leehalliday -

    No, this fix is completely separate from what miickel posted (which didn't work for me, couldn't get the permalinks would work). So I took a closer look at the plugin's code and figured out how to get it to pull the correct thumbnail.

    replace array($tbWidth) [no quotes in the actual code] with 'thumbnail' [single quotes included].

  10. leehalliday
    Member
    Posted 3 years ago #

    Howdy,

    Well this is very close to what I need however there is still a small issue with I put 'thumbnail' and set the widget to select own images then they all appear 150px by 150px which is sort of what I want but 30px x 30px. Also If I change 'thumbnail' to '30' then the images appear but at there actually size which can be huge.

    So can you help in getting them to 30 x 30 please?

    Lee

  11. leehalliday
    Member
    Posted 3 years ago #

    There no help for my issues, this makes me a sad panda!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic