• I am using the WP thumbnail function on my blog: https://robcubbon.com/blog

    This is what I have in my functions.php

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 150, true );

    I would like to set up a custom template page where I will re-list the last 5 or 10 blog posts in the footer with a much smaller thumbnail, say 50px by 50px.

    Would the best way to do this be with a custom field that specifies an image route of the 50px thumbnail which I could then call in the page template or is there a better way of doing it with WP’s post-thumbnails?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can set another thumbnail. For example, if you add this to your function:

    add_image_size( ‘my_thumbnail’, 50, 50, true );

    You would then call that preset by using the following:

    <?php the_post_thumbnail(‘my_thumbnail’); ?>

    Thread Starter Rob Cubbon

    (@robcub)

    Thank you, SteelFrog.

    I’m having trouble implementing it on my custom page. I’ve put this after the loop which I’ve adapted from a bit of PHP from my sidebar that lists my last 10 posts.

    It doesn’t show the thumbnails and has the permalinks and titles wrong – it returns the permalink (?n – not pretty) and title of the page you are on.

    <ul>
    <?php
    $myposts = get_posts('numberposts=10');
    foreach($myposts as $post) :
    ?>
    <li> <?php the_post_thumbnail('my_thumbnail'); ?> <a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
    <?php endforeach; ?>
    </ul>

    And when I put it in the sidebar the list of posts are OK but the new thumbnails are all of the post you are on rather than the post it is next to in the list.

    It looks like the thumbnail call should have the post id on it?

    Thread Starter Rob Cubbon

    (@robcub)

    This seems to work better:

    <ul>
    <?php $my_query = new WP_Query('showposts=10'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li><?php the_post_thumbnail('my_thumbnail'); ?></li>
    <li><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    But, it’s funny, sometimes it takes the 150px x 150px post thumbnail and resizes it to 50px x 50px and sometimes it take the first image from the post and resizes it to 50px wide by whatever the proportionate height. So it ignores some specified thumbnails!?

    Thread Starter Rob Cubbon

    (@robcub)

    I’ve just found a way round it.

    When I’d specifically created a 150px square image for the main post thumbnail and uploaded it; WP uses that 150px x 150px image to make the new thumbnail. Where I’d chosen an image of another size from the media library and used the 150px square version that it created for the main thumbnail; WP uses the original image from the media library to make the new sized thumbnail which is why they came in all shapes and sizes.

    So I have just made sure that the last few posts have proper specifically uploaded square thumbnails and that makes the secondary size of thumbnails square.

    Confused? I am.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Two different sizes of thumbnails’ is closed to new replies.