WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] the_post_thumbnail() not working for pages

[Resolved] the_post_thumbnail() not working for pages

  • After upgrading my wordpress to the latest version thumbnails are no longer working for pages, only posts..

    I have not changed any theme files and everything is the same.

Viewing 13 replies - 1 through 13 (of 13 total)
  • esmi

    @esmi

    Forum Moderator

    Unless you provide a link to a page demonstrating the problem, no one will be able to offer much in the way of assistance. In the meantime, have you tried:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the Twenty Ten theme to rule out any theme-specific problems.

    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

    Have tried all of these.

    Deactivated all the plugins, but still no page thumbnails.

    Also switched to the TwentyTen theme – no luck.

    Reset plugins via phpmyadmin, still nothing.

    The site url is universityhoodiesdirect.com.
    This is becoming quite frustrating!

    esmi

    @esmi

    Forum Moderator

    Can you post a link to a page that demonstrates your problem?

    Yep, link is here.

    The parent page lists all child pages. The blank space to the left of the name and description is where the_post_thumbnail() should be displaying the image.

    Code being used is like this

    <?php
    $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID."	AND post_type = 'page' ORDER BY menu_order", 'OBJECT');	?>
    <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
    <? $pricefrom = get_post_meta($pageChild->ID, 'Quantity24', $single = true); ?>
    <? $colours = get_post_meta($pageChild->ID, 'Colours', $single = true); ?>
    <? $smalldescrip = get_post_meta($pageChild->ID, 'SmallDescrip', $single = true); ?>
    <? $OutlineImg = get_post_meta($pageChild->ID, 'OutlineImg', $single = true); ?>
    <? $ProductCode = get_post_meta($pageChild->ID, 'ProductCode', $single = true); ?>
    <a href="<?php echo  get_permalink($pageChild->ID); ?>"><?php the_post_thumbnail(array(150,150)); ?></a>
    <h2 class="gridtitle"><a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><? echo $ProductCode ?>  <?php echo $pageChild->post_title; ?></a></h2>
    <?php endforeach; endif; ?>

    Edit ‘i’ve removed some non essential bits such as formatting to reduce post size.

    esmi

    @esmi

    Forum Moderator

    I’d suggest that you start by using <?php and not <?

    Have applied recommended suggestion, however, the problem persists

    Moderator keesiemeijer

    @keesiemeijer

    I think this is not within the loop. Try it with get_the_post_thumbnail

    I think this is not within the loop. Try it with get_the_post_thumbnail

    Thanks this is now partially working using the following
    <?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail', array(150,150)); ?>

    However, on the homepage I have a div on the left with ‘featured products’ and also on the product pages there is a similar products div (on the right). I only want these thumbnails to be 50px wide so I change the array to array(50,50). However these show at 150x150px.

    Any ideas?

    Moderator keesiemeijer

    @keesiemeijer

    the arguments (parameters) for get_the_post_thumbnail() function are: get_the_post_thumbnail( $id, $size, $attr );
    try it with:

    <?php echo get_the_post_thumbnail($pageChild->ID, array(50,50)); ?>

    <?php echo get_the_post_thumbnail($pageChild->ID, array(50,50)); ?>

    I am trying it with the above code you suggested. As you can see here the two featured products thumbnails are now smaller in size but are not rectangular.

    I have also added the following into my themes function file

    add_theme_support( 'post-thumbnails' );
    
    	if ( function_exists( 'add_theme_support' ) ) {
    		add_theme_support( 'post-thumbnails' );
    	        set_post_thumbnail_size( 50, 50 ); // default Post Thumbnail dimensions
    	}
    
    	if ( function_exists( 'add_image_size' ) ) {
    		add_image_size( 'featured-thumb', 50, 50 );
    		add_image_size( 'featured-product-thumb', 100, 100 );
    	}

    So when using <?php echo get_the_post_thumbnail($pageChild->ID, 'featured-product-thumb') ?> I expect the thumbnails to be 100x100px. Instead they are 100px high and a different width.

    Any idea?

    Thanks for help so far!

    Moderator keesiemeijer

    @keesiemeijer

    try add_image_size croppped mode:

    if ( function_exists( 'add_image_size' ) ) {
    		add_image_size( 'featured-thumb', 50, 50, true );
    		add_image_size( 'featured-product-thumb', 100, 100, true );
    }

    Thanks so much keesiemeijer. Very helpful.

    For anyone else reading.. you will have to remove existing featured images and then re upload a new featured image for each post. Changes will then take effect.

    Moderator keesiemeijer

    @keesiemeijer

    You’re welcome. please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] the_post_thumbnail() not working for pages’ is closed to new replies.
Skip to toolbar