Andi Wilkinson
Andi Wilkinson

Reputation: 662

display three post items in a column

I am using the following code from the codex to put the last three posts in a box on a home page - i will also be doing a similar thing with a custom post type of 'event dates'

rookie question I know but how will I get it to display post content as well as title? - whenever I try to add content it displays the page content not the post content!

TIA

<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
}
?>

Upvotes: 0

Views: 81

Answers (1)

Christopher Ellis
Christopher Ellis

Reputation: 1116

Here is a example for you. Displays column or box title, post title, date, excerpt, and thumbnail. You can strip out the parts you want to use and of course you will have to style with your own css. Hope it helps.

<div id="col-1">
    <h4>News & Events</h4>
    <?php $counter = 3;
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=3');?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>

    <div id="col1left">
        <?php the_post_thumbnail(); ?>
    </div><!-- CLOSE COL1LEFT -->

    <div id="col1right">
        <div class="NE_title">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </div><!-- CLOSE NE_TITLE -->
        <div class="NE_date">
            <?php the_date(); ?>
        </div><!-- CLOSE NE_DATE-->
        <p><?php echo get_excerpt(75); ?></p>
    </div><!-- CLOSE COL1RIGHT -->
        <?php endwhile; ?>    
</div><!-- CLOSE COLUMN-1 -->

Upvotes: 1

Related Questions