• Resolved Antscran

    (@antscran)


    Hi all,

    I am building a child theme off the Twenty Twelve default theme, and having an issue displaying my custom image size, I had previously had this code working on a basic theme I put together from scratch but no joy getting it to work properly so far.

    The current result that is displayed can be found here

    https://coder-tronics.com/articles-2/

    I have a fair bit of code for the custom post type which for the most part seems to be working, in the back administration panel, the code for the custom image size in the functions.php file is below:

    /* CUSTOM POST THUMBNAILS --------*/
    if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support('post-thumbnails');
    add_image_size('custom-portfoliothumb', 320, 120);
    }

    And I am using this on a custom page template in this way:

    <div id="portfolio-item">
    <h2><?php the_title(); ?></h2>
    "><?php the_post_thumbnail('custom-portfoliothumb');?>
    <?php the_excerpt(); ?>
    </div>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Obviously I am doing something wrong but not quite sure yet, hence the question. I have tried looking at the result in firebug but no clues as yet, as I said the code did work in basic theme, so I believe the code is not interacting with Twenty Twelve as it should. Fairly new to the child theme idea and Twenty Twelve.

    I can post more code if required but didn’t want to place too long a post.

    Cheers,

    Ant

Viewing 7 replies - 1 through 7 (of 7 total)
  • It’s the 3rd parameter in add_image_size() should be true so that it hard crops, if not images will be cropped based on one size. That’s why you get 120px height with a width value in proportion to the actual image.
    https://codex.www.ads-software.com/Function_Reference/add_image_size

    Also, I think there is no need to add_theme_support('post-thumbnails') because parent theme already does that. And the if exists for add_theme_suppor() is not necessary anymore, it’s for a very old version of WP.

    So we will have something like this.

    function mychildtheme_setup() {
    	add_image_size( 'custom-portfoliothumb', 320, 120, true );
    }
    
    add_action( 'after_setup_theme', 'mychildtheme_setup' );

    and call it like what you did.

    Remember that any changes to image settings will not affect to ones already uploaded, so you have to delete and reupload or use Regenerate Thumbnails plugin to help in case there are lots of images.
    https://www.ads-software.com/plugins/regenerate-thumbnails/

    Thread Starter Antscran

    (@antscran)

    Hi Paul,

    Thanks for the prompt and clear response.

    Tried the code as you posted, I can rename the function name later. I also deleted the images and re-uploaded (been caught by that before, thanks for the reminder though).

    The arrow image is actually 320*120 just for testing, but I am still having what I believe to be an issue. I say believe as it seems to be working on some level, cropping and resizing but not as expected.

    The arrow image is larger now than before, but surely if it is already 320*120, there should be no cropping with the ‘true’ parameter you mentioned?

    Best regards,

    Ant

    Hi Ant, try again for the arrow image, this time rename the image file to not only having numbers.

    Try a name like myarrow.png

    Thread Starter Antscran

    (@antscran)

    Hey Paul,

    Again thanks for your input on this. Gave that a go but the image is still cropping to 195*120.

    I am now thinking that the other PHP code I am using must be causing an issue with Twenty Twelve, as I had this working on a basic theme I made which can be seen here (I integrated the twenty twelve menu into it, but the main structure is all my own)

    https://simples.net23.net/

    The code gives me a menu in the administration panel called Portfolio, then I add a post and the image that is shown is chosen via the ‘Featured Image’ menu, but this always comes up with 195*120 for the arrow.png.

    I appreciate you may not be able to answer this Paul as straying into other potential issues, but any further pointers would be great.

    Cheers,

    Ant

    Hi Ant, I just tested it in my local install of 2012 childtheme using that same function and calling it in a page template.

    I upload this image 320×120 to be exact
    https://dummyimage.com/320×120/000/fff.png

    and it displays in the page with the same dimension, no crop. Meaning the function works as intended.

    Thread Starter Antscran

    (@antscran)

    Paul,

    Cheers for testing this, and bemused as your code looked fine and now confirmed. Will check my installation as had a weird issue before which I could not solve, re-installed WordPress and the same functions.php file worked perfectly the next time around.

    Cheers,

    Ant

    Thread Starter Antscran

    (@antscran)

    Marked as resolved

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Twenty Twelve Custom Post Image’ is closed to new replies.