Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/02/2013, 16:58
destinopolinesia
 
Fecha de Ingreso: mayo-2011
Mensajes: 167
Antigüedad: 12 años, 11 meses
Puntos: 6
1a foto en volcado de posts por categorias funciona a lo loco

Efectivamente, a mi tema wordpress le he metido estos dos trozos de codigo:

1) ESTE DE AQUI PARA ASIGNAR A LA PRIMERA FOTO DE CADA POST LA CALIDAD DE FOTO THUMBNAIL:

function auto_post_thumbnail() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numb erposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
} else {
set_post_thumbnail($post->ID, 'ID_imagen_por_defecto'); //aqui pon la ID de la imagen por defecto si quieres una imagen por defecto cuando no haya imagenes que destacar. Si no quieres ninguna modifica el codigo a tu gusto.
}
}
}

add_action('the_post', 'auto_post_thumbnail');
add_action('save_post', 'auto_post_thumbnail');
add_action('draft_to_publish', 'auto_post_thumbnail');
add_action('new_to_publish', 'auto_post_thumbnail');
add_action('pending_to_publish', 'auto_post_thumbnail');
add_action('future_to_publish', 'auto_post_thumbnail');

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true );
add_image_size( 'teaser', 150, 150, true );

2) EL SEGUNDO ESTE DE AQUI QUE ENCONTRE POR INTERNET PARA QUE AL VOLCAR EL EXCERPT DE LOS POSTS POR CATEGORIAS ME INCLUYA ESA FOTO THUMBNAIL ENTRE EL TITULO DEL POST Y EL TEXTO DESCRIPTIVO:

function custom_excerpt_box() { ?>
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
<div id="text_area_excerpt">
<?php echo '<p>' . get_the_excerpt() . ''; ?></p></div>
<?php }
add_filter('the_excerpt', 'custom_excerpt_box');

// Teaser Length
function teaser_length($length) {
return 47;
}
add_filter('excerpt_length', 'teaser_length');

Pues bien el problema como vereis por ejemplo en este volcado de una de las categorias http://tatouages-polynesiens.polines...prix-tatouage/ es que en algunos posts funciona y muestra la foto y en otros NO.

He intentando averiguar porque pero no encuentro ninguna razon logica de porque a veces funciona y otras veces no.

Esperando que vosotros podais ayudarme os doy las gracias por anticipado y os envio un cordial saludo