Hide missing image icon for Tim Thumb
-
Hi guys
I am using a Tim Thumb script to show featured images from posts on the home page, using the Advanced Custom Fields plugin. All works very well.
However, if a user decides not to enter all the images (not all are mandatory) I am left with a broken/missing image icon. Is there some PHP I can include to detect if there is no image and then not show the broken image icon?
Many thanks,
Ian
-
Hi guys
This isn’t actually related to Tim Thumb script I guess. I’ve now changed this to include a lightbox on clicking on any image, so the original image is used too in the lightbox.
As I’m using custom fields to show the 7 images, but not all are mandatory, there is likely to be (a) a broken image icon on the page for any missing images and (b) a broken lightbox experience where the missing images are.
I found this post but I am not sure how to use this solution:
Here is my code for each image:
<a href="<?php the_field('featuredimage' ); ?>" rel="lightbox" title="<?php the_field('featured_image_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('featuredimage' ); ?>&w=607&zc=1" alt="Post Image" class="postimgthumb" /></a>
<?php if (trim(the_field('featuredimage' )) != ''){ ?> <a href="<?php the_field('featuredimage' ); ?>" rel="lightbox" title="<?php the_field('featured_image_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('featuredimage' ); ?>&w=607&zc=1" alt="Post Image" class="postimgthumb" /></a> <?php }?>
Works perfectly – thanks!!!
Actually so sorry – my test was wrong. It has worked on the fields that have no image, but on the others, it is rendering the image URL instead of the image….
So it just puts the image url in text on the page – any ideas?
so it’s doing it even for ones where the image is bust – link please, or full code of where you’re getting the featured image from. Also is it genuinely the featured image of a post and are you in the loop or outside ?
Hi there
It’s showing the URL for the images that ARE there. Where the image is missing it works, and hides correctly.
So the broken images are working, as I hoped. But the images that are there, spit out the image url instead of the image itself.
This is inside the loop and it is a custom field called featured image:
<?php /* Start loop */ ?> <?php while (have_posts()) : the_post(); ?> <article <?php post_class() ?> id="post-<?php the_ID(); ?>"> <header> <h1 class="entry-title"><?php the_title(); ?></h1> <?php reverie_entry_meta(); ?> </header> <div class="entry-content"> <div class="projectDetails"> </div> <?php the_content('Continue...'); ?> <a href="<?php the_field('featuredimage' ); ?>" rel="lightbox" title="<?php the_field('featured_image_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('featuredimage' ); ?>&w=770&zc=1" class="post<?php the_category_unlinked(' '); ?> alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('featured_image_description'); ?></p> <a href="<?php the_field('another_project_image-1' ); ?>" rel="lightbox" title="<?php the_field('image_1_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-1' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_1_description'); ?></p> <a href="<?php the_field('another_project_image-2' ); ?>" rel="lightbox" title="<?php the_field('image_2_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-2' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_2_description'); ?></p> <a href="<?php the_field('another_project_image-3' ); ?>" rel="lightbox" title="<?php the_field('image_3_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-3' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_3_description'); ?></p> <a href="<?php the_field('another_project_image-4' ); ?>" rel="lightbox" title="<?php the_field('image_4_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-4' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_4_description'); ?></p> <a href="<?php the_field('another_project_image-5' ); ?>" rel="lightbox" title="<?php the_field('image_5_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-5' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_5_description'); ?></p> <a href="<?php the_field('another_project_image-6' ); ?>" rel="lightbox" title="<?php the_field('image_6_description'); ?>"><img src="<?php echo get_option('siteurl') ?>/wp-content/themes/reverie/scripts/timthumb.php?src=<?php the_field('another_project_image-6' ); ?>&w=770&zc=1" alt="Post Image" class="postimgthumb" /></a> <p><?php the_field('image_6_description'); ?></p> <p>Name: <?php the_field('project_name'); ?></p> <p>Location: <?php the_field('location'); ?></p> <p>Client: <?php the_field('client'); ?></p> <p>Project Year: <?php the_field('project_year'); ?></p> <p>Project Sector: <?php the_field('project_sector'); ?></p> <p>Cost: £<?php the_field('cost'); ?></p> <?php the_field('project_summary'); ?> <div class="postmeta"> <a href="<?php the_permalink() ?>#commenting" title="View Comments"> <div class="postFooter"> <div class="postFooterLeft"> <span class="comm"><?php comments_number('0 Comments','1 Comment','% Comments'); ?></span></a> <span class='st_email_hcount' displayText='Email'></span><span class='st_twitter_hcount' displayText='Tweet'></span><span class='st_fblike_hcount' ></span> </div><!--/postFooterLeft--> </div><!--/postFooter--> <br class="clearBoth"> </div><!--/postmeta--> </div> <footer> <?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'reverie'), 'after' => '</p></nav>' )); ?> <p><?php the_tags(); ?></p> </footer> <?php comments_template(); ?> </article> <?php endwhile; // End the loop ?>
Can anybody help with this one? thanks
need a link probably – either your version of php has no support for files using fopen, you’re not running the latest version of timthumb, the url is wrong, the image is cmyk jpeg or mod_security is installed and is messing up the timthumb install.
use phpinfo to check if allow_url_fopen is set (in safe mode it won’t be)
check timthumb version by going to appearance, select timthumb in list of files, check version is something like 2.8.11
get the url of one of the images and repaste to another tab in your browser – does it show, if not is it a 404 or broken image icon ?
mod_security is a bit more of a pain
Thanks loads, timthumb version was out of date.
- The topic ‘Hide missing image icon for Tim Thumb’ is closed to new replies.