Ocultar imagen predeterminada en loop de primeras imágenes

  • Autor Autor xxxronaldxxx
  • Fecha de inicio Fecha de inicio
X

xxxronaldxxx

Beta
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Hola a todos, tengo un problema
En mi archivo functions.php tengo agregado el siguiente codigo:
PHP:
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 = "/images/default.png";
  }
  return $first_img;
}

Como hago que en vez de mostrarme el default.png no me muestre ninguna imagen, es decir; que se oculte que no aparesca

tengo este otro codigo en el index:
PHP:
<img src="<?php echo get_bloginfo('template_url')?>/thumb/timthumb.php?src=<?php echo catch_that_image() ?>&w=227&h=136" class="first_img"/>
le tengo que agregar algo? algun if o else?

Gracias por las respuestas que me puedan brindar.
Saludos!
 
No entendí completamente lo que describes.

Pero eliminando este fragmento, la imagen que se muestra cuando no existe una, deja de mostrarse.
PHP:
  if(empty($first_img)){ //Defines a default image 
    $first_img = "/images/default.png"; 
  }
 
Si no quieres que te muestre ninguna imagen, porque no solo eliminas esas lineas y ya?

No te entiendo muy bien a que te refieres :S
 
Insertar CODE, HTML o PHP:
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]; 

  return $first_img; 
}

y

Insertar CODE, HTML o PHP:
<img src="<?php echo get_bloginfo('template_url')?>/thumb/timthumb.php?src=<?php echo catch_that_image() ?>&w=227&h=136" class="first_img"/>

así

Insertar CODE, HTML o PHP:
<?php 
$catch=catch_that_image();
if($catch!=''){
?>
<img src="<?php echo get_bloginfo('template_url')?>/thumb/timthumb.php?src=<?php echo $catch; ?>&w=227&h=136" class="first_img"/>
<?php } ?>
 
Hola, intenta esto:
para functions.php
PHP:
<?php
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)){ //Le agregas un valor nulo
    $first_img = null; 
  } 
  return $first_img; 
}  

?>


en el loop:

PHP:
<?php if( catch_that_image() != null): ?>
<img src="<?php echo get_bloginfo('template_url')?>/thumb/timthumb.php?src=<?php echo catch_that_image() ?>&w=227&h=136" class="first_img"/>
<?php endif ?>


...no lo he probado, pruébalo y me citas en un comentario si funciona o no, saludos.