Thanks esmi! It works as i want but i dont know what happens with the thumbnail. It shows different in the sidebar than in the content. This is the code in index:
</p>
<a href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
<?php the_excerpt(); ?>
And i ve put in the sidebar like:
<?php
$side_posts = get_posts('numberposts=5&offset=10');
foreach($side_posts as $post) :
setup_postdata($post); ?>
<li><p><a href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p></li>
<?php endforeach; ?>
</ul>
<?php wp_reset_query();?>
But the image post is bigger than in the index...
By the way, this are the lines about thumbnail in functions.php:
# Displays post image attachment (sizes: thumbnail, medium, full)
function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') {
if ($postid<1) $postid = get_the_ID();
if ($images = get_children(array(
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
foreach($images as $image) {
$attachment=wp_get_attachment_image_src($image->ID, $size);
?><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /><?php
}
}
Any help with this?