something like this:
$first_img = '';
if not – maybe you have to explain in more detail what ‘absolutely nothing’ means in this case.
Instead of showing the little image box with an X in it which denotes the image not being found I would like it to act as if no image is there at all.
that part is not in your posted code – can you post the template file where the function is used?
please paste the code into a http://wordpress.pastebin.com/ and post the link to it here
That’s just it, it doesn’t call for this anywhere in the code, so posting that information will not help. Instead of returning an image I would like to return nothing.
the function only returns the image url – or nothing.
to show the image you have to use probably some code like this:
<img src="<?php echo catch_that_image(); ?>" alt="" />
where in your other template files are you using this function?
try changing this line to:
<?php $image = catch_that_image();
if( $image ) { ?>
<img src="<?php echo $image; ?>" alt="" />
<?php } ?>
This is the code I’m using
<a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" class="index" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" /></a>
That last code still doesn’t do what I’d like it to.
That last code still doesn’t do what I’d like it to.
how did you integrate it?
<?php if( catch_that_image() != '' ) { ?>
<a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" class="index" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" /></a><?php } ?>
this is assuming that you implemented
if(empty($first_img)){ //Defines a default image
$first_img = '';
}
into the catch_the_image() code.
This is what I have…
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = ' ';
}
return $first_img;
}
And in the index it does not work with the original code and does not work with the code provided. :-S
$first_img = ' '
in your code, you have a space character between the single quotes – ' ' is different from ''
try and correct this.
you need to have '' in your function – two consecutive single quotes with nothing inbetween.