• On my homepage I am showing thumbnails and title from a list of posts from a particular category.

    The problem is it works fine on my local machine but doesn’t work on my live site.

    in functions.php I have:

    function get_the_thumbnail() {
    $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
      if($files) :
        $keys = array_reverse(array_keys($files));
        $j=0;
        $num = $keys[$j];
        $image=wp_get_attachment_image($num, 'large', false);
        $imagepieces = explode('"', $image);
        $imagepath = $imagepieces[1];
        $thumb=wp_get_attachment_thumb_url($num);
        print "<img src='$thumb' class='thumbnail' />";
      endif;
    }

    it’s called in page.php (homepage) is:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<?php
    	if (is_front_page()) {
    	        query_posts('cat=19&showposts=12');
    	}
    	?>
    	<div class="image-box" id="post-<?php the_ID(); ?>">
    		<a href="<?php the_permalink(); ?>">
    			<?php get_the_thumbnail(); ?>
    			<p><?php the_title(); ?></p>
    		</a>
    	</div>
    	<?php endwhile; endif; ?>

    As I say it works fine on my local machine. The images do exist, it’s just the html doesn’t display.

    The output should be (locally):

    <a href="https://127.0.0.1/~mysite/mysite/?p=931">
        <img class="thumbnail" src="https://127.0.0.1/~mysite/mysite/wp-content/uploads/2010/03/38_okgoposalbum-140x140.gif">
        <p>OK GO Album cover</p>
    </a>

    but on my site I get:

    <a href="https://www.mysite.com/?p=931">
    	<p>OK GO Album cover</p>
    </a>

    It’s completely stumped me. I’ve tried alternative thumbnail plugins like get-the-image and it also fails to show thumbnails online (they show locally). I’ve changed permissions of the upload folder and all the images inside.

    What could be the problem? I’m so close!

Viewing 2 replies - 1 through 2 (of 2 total)
  • If it was me, I’d start just before $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image'); and try printing out the variables at each stage. So something like:

    $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
    echo '<pre style="display:none;">';
    print_r($files);
    echo '</pre>';

    If necessary, dump variables like $keys both before and after processing so that you’re checking what’s going in and what comes out. That should help you to pinpoint where the code is failing on the live site by dumping the variables into the source but not the displayed page. With luck, you’ll be able to narrow it down to a specific PHP function.

    Every time I’ve come across this kind of problem (and I hit one just like it yesterday), it seems to boil down to a slightly different PHP setup between the local and remoter servers.
    So I’ll then try to avoid the problem function by approaching the issue from another angle.

    Hope that helps.

    Thread Starter jeremygillies

    (@jeremygillies)

    Thank you for your quick reply.

    The function’s not returning anything. You could be right about the configuration differences between local and live. It’s fair to say I’m no seasoned PHP coder – more of a tweaker, but I get what you’re suggesting. Still no luck though.

    Local:

    <div id="post-931" class="image-box">
    			<a href="https://127.0.0.1/~mysite/mysite/?p=931">
    				<pre style="display: none;">Array
    (
       [932] => stdClass Object
           (
               [ID] => 932
               [post_author] => 1
               [post_date] => 2010-03-25 00:06:28
               [post_date_gmt] => 2010-03-25 00:06:28
               [post_content] =>
               [post_title] => 38_okgoposalbum
               [post_excerpt] =>
               [post_status] => inherit
               [comment_status] => open
               [ping_status] => open
               [post_password] =>
               [post_name] => 38_okgoposalbum
               [to_ping] =>
               [pinged] =>
               [post_modified] => 2010-03-25 00:06:28
               [post_modified_gmt] => 2010-03-25 00:06:28
               [post_content_filtered] =>
               [post_parent] => 931
               [guid] => https://127.0.0.1/~mysite/mysite/wp-content/uploads/2010/03/38_okgoposalbum.gif
               [menu_order] => 0
               [post_type] => attachment
               [post_mime_type] => image/gif
               [comment_count] => 0
               [filter] => raw
           )
    
    )
    </pre>				<p>OK GO Album cover</p>
    			</a>
    		</div>

    Live:

    <div id="post-931" class="image-box">
    			<a href="https://www.mysite.com/?p=931">
    				<pre style="display: none;">Array
    (
    )
    </pre>				<p>OK GO Album cover</p>
    			</a>
    		</div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Thumbnails not showing on live site’ is closed to new replies.