Hi all, I have the solution, so i share the love with you, even if the help her it’s so so hard ??
in this exemple i set a custom field with value “petit” who will print in my template the URL of my Thumbnail image, so the user forget to put the url in the custom field, the script will automatically print a URL to an image i set in the images folder named : no-img.jpg . Magic ?? in this way you saved the look of ur website and esigne too :
<?php
$values = get_post_custom_values("petit"); // set the img custom name
if (isset($values[0])) { // if there's a img in my custom field
?>
<img src="<?php $values = get_post_custom_values("petit"); echo $values[0]; ?>" title="<?php the_title(); ?>"/>
<?php } // end if statement
// if there's no img do replace it with no-img
else { ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/no-img.jpg" title="<?php the_title(); ?>"/>
<?php } ?>
Another way :
<?php // set the img custom name + get the data of custom_values.
if($value !== get_post_custom_values("petit")) {
?>
<!--Print the data of custom_values if exist, if not next line-->
<img src="<?php $values = get_post_custom_values("petit"); echo $values[0]; ?>" title="<?php the_title(); ?>"/>
<?php } // end if statement
// if there's no data in custom_values print this line code : url of no-img.jpg
else { ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/no-img.jpg" title="<?php the_title(); ?>"/>
<?php } ?>
et Voila the latest all i have:
<?php
$pattern = "/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i";
preg_match_all($pattern, $post->post_content, $images);
if(!$images[1][0]) {?>
<img src='<?php bloginfo("template_url");?>/i/sorry-no-photo.png' alt='Sorry! No image was found.' width='75px' />
<?
}
else
echo "<img src='".$images[1][0]."' width='75px' />";
?>
that’s all, i shared my lovely php code just for YOU.