• Couldn’t find this answer in the forum, so hopefully this is easy enough to do. Basically I would like to have two different sizes available for the ‘featured image’. The only time I will use the other is when my featured image is an infographic, for example. All other times, the default size/crop is just fine.

    OK, my theme has the following size in functions for the featured image:

    add_image_size( 'single-large', 564, 272, true ); // Single post/page large

    and appears in single.php as

    <?php the_post_thumbnail('single-large'); ?>

    which is fine (and I’d like to keep all other posts just like this except those that need this other size). But I need just one more size available for ones that need to be longer height. Is this possible?

    I know I can ‘insert’ an image, but that won’t make it a featured image and it won’t appear as a thumbnail on the homepage or categories.

    I’ve added a new image size of:

    add_image_size( 'single-large-graphic', 564, 1000, true );

    but not sure how to make that an additional option for a featured image should I want it for a specific image/post.

    Any ideas? Thank you to the coders out there ?? ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • Post_Thumbnails
    scroll down, it has info which pertains to this:)

    Thread Starter alanpeto

    (@alanpeto)

    Thanks deepbevel! I looked through it, but it looks like what I already have?? Is there a specific portion I should be looking at?

    I already have functions.php specify the two versions of the image sizes I want. But how do you specify on single.php which one you want? When you add a featured image to the post, it doesn’t give you the option to specify…but inserting an image does (but that doesn’t make it a featured image).

    I’m lost ??

    maybe you could use either conditionally by category or tag.

    I’m no php pro but I think this would do it,

    <?php if (in_category('category-slug')) { ?>
    
    <?php the_post_thumbnail('single-large'); ?>
    
    <?php } ?>
    
    <?php if (in_category('category-slug')) { ?>
    
    <?php the_post_thumbnail('single-large-graphic'); ?>
    
    <?php } ?>

    just use the whole thing in place of:

    <?php the_post_thumbnail();?>

    If not this conditional, perhaps one like it would do what you need.

    Thread Starter alanpeto

    (@alanpeto)

    I love it…worked!! ??

    That actually solved another problem of mine also! The only downside is if someone wants to add more categories they would need to update their single.php as well. But I’m set in mine, so this works perfect (although I’d be interested if there was another way also…I like to keep things automated).

    Thank you again deepbevel!

    let me dwell on it.

    You could do a separate post template for each size thumbnail. then your users could choose a template from the post editor.
    ?

    or, you could put a conditional in single.php, directing all posts to use the current post template for one size, and another post template for the other size, depending on the tag.?

    then users could simply add a tag “large” or “small” to their post and get the appropriate image size.

    Thread Starter alanpeto

    (@alanpeto)

    I like the tag option! Have you done this before? I’m horrible at coding myself but can tinker around with help ??

    in single.php,

    before the loop

    <?php if( has_tag('small') ) :
    include 'small-img-template.php';?>
    
    <?php } ?>
    
    <?php if( has_tag('large') ) :
    include 'large-img-template.php';?>
    
    <?php } ?>

    don’t know if that’s possible or not, or something like it, I probably didn’t do it right but I’ll try it soon. or please, be my guest… :}

    Thread Starter alanpeto

    (@alanpeto)

    I’m going to try this tomorrow and let you know ??

    but you’ll need to make the custompost templates. You might as well, if it doesn’t work this way, there will still be more options with seperate templates.

    A custom post template can be as simple as a copy of your current single.php but with a different name, so this at the very top of the page, right before “get the header”

    <?php
    /*
    Template Name Posts: Name your template here
    */
    ?>

    everything will be the same except the thumbnail code.

    do this in a text editor, then name it and save as “your-custom-post-name.php”

    then upload it to your theme’s folder.

    then if you get this plugin, the optional template is available in the post editor, you can select it from a drop down.

    This is probably not the most elegant or simplist solutiom but it should work to allow you to assign custom post templates based on categories, which are auto-assigned by tag.

    So, if you had a tag for large images “large” it could be automatically assigned to a category called “large”. from there, all posts with in the “Large” category can be assigned a specific post template.
    thread, check last post

    It involves putting code in functions.php and default single.php, -still looking for an all in one method.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Multiple php the_post_thumbnail sizes’ is closed to new replies.