Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am editing a costum theme. I was trying to add excerpt to the homepage. The homepage is costum.

The excerpt show just fine but the image refuses to be displayed it seems.

This is my code:

$args = array( 'numberposts' => 5, 'category' => 3,4,5,6,7 );
$posts = query_posts( $args . '&orderby=date&order=desc' );
foreach( $posts as $post ) :    setup_postdata($post); ?>
<li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="postcont">
        <?php 
        echo get_post_meta($post->ID, "Thumbnail", true);
        the_excerpt();  ?>
    </div>
</li>
<?php endforeach; ?>

This is of course added to functions.php

if ( function_exists( 'add_theme_support' ) ) { 
add_theme_support( 'post-thumbnails' ); 
}

Any toughts?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you add support for Post Thumbnails, you can use its own function instead of get_post_meta(), see codex for more information - http://codex.wordpress.org/Post_Thumbnails#Function_Reference

Use following code in your theme:

<div class="postcont>        
<?php
    if ( has_post_thumbnail() ) {
        the_post_thumbnail();
    }
    the_excerpt();
?>
</div>

EDIT

And using the OP's code:

$args = array( 'numberposts' => 5, 'category' => 3,4,5,6,7 );
$posts = query_posts( $args . '&orderby=date&order=desc' );
foreach( $posts as $post ) :    setup_postdata($post); ?>
<li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="postcont">
        <?php 
        if ( has_post_thumbnail() ) {
            the_post_thumbnail();
        }
        the_excerpt();  ?>
    </div>
</li>
<?php endforeach; ?>
share|improve this answer
    
Thanks. This solved the problem –  Jarco Sep 20 '11 at 14:18
    
Thanks Chip for editing, I didn't have much time when writing this snippet. BTW @Jarco query_posts() is for modifying default query, if you want to get array of post for secondary listing use get_posts() function –  Mamaduka Sep 20 '11 at 18:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.