WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_post_thumbnail() not working for pages (14 posts)

  1. jainsy
    Member
    Posted 3 years ago #

    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.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  3. jainsy
    Member
    Posted 3 years ago #

    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!

  4. esmi
    Forum Moderator
    Posted 3 years ago #

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

  5. jainsy
    Member
    Posted 3 years ago #

    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.

  6. esmi
    Forum Moderator
    Posted 3 years ago #

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

  7. jainsy
    Member
    Posted 3 years ago #

    Have applied recommended suggestion, however, the problem persists

  8. keesiemeijer
    moderator
    Posted 3 years ago #

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

  9. jainsy
    Member
    Posted 3 years ago #

    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?

  10. keesiemeijer
    moderator
    Posted 3 years ago #

    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)); ?>
  11. jainsy
    Member
    Posted 3 years ago #

    <?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!

  12. keesiemeijer
    moderator
    Posted 3 years ago #

    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 );
    }
  13. jainsy
    Member
    Posted 3 years ago #

    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.

  14. keesiemeijer
    moderator
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic