Support » Fixing WordPress » Pull Most Recent Post Excerpt

  • Hello,
    I am trying to pull an excerpt of the most recent post made in my blog to my static main page via php, I can get a certain post by using this:

    <?php
    $new_id = 1;
    $post_id = get_post($new_id);
    $title = $post_id->post_content;
    echo($title);
    ?>

    But I want an excerpt from the newest post made if possible or just how to get it’s ID would be great. Thank you for any advice!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Brayne

    (@brayne)

    This works for me.

    <?php $postslist = get_posts('category=1&numberposts=1&order=DESC&orderby=post_date');
    foreach ($postslist as $post) :
    setup_postdata($post); ?>
    <div class="post_item">
    <span class='side_date'><?php the_time('F j, Y'); ?></span><br />
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    </div>
    <?php endforeach; ?>

    Hi, I´m trying to show last post on my home page and I try using your code
    THe thing is I will like to show lastes post but excluding some categories. So with out know well programming I just copy&paste your code and made this modification but still showme a post that I put on the exclude.

    <div id="lastest-post">
    	   	<?php $postslist = get_posts('numberposts=1&order=DESC&orderby=post_date&exclude=142,143,144,157');
    		foreach ($postslist as $post) :
    		setup_postdata($post); ?>
    		<div>
    			<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    			<h4><?php the_excerpt(); ?></h4>
    		</div>
    		<?php endforeach; ?>
    	</div>

    Any advice ?

    Try reading the Docs: Template_Tags/get_posts

    What you did: excluded the posts having those IDs. If you want to exclude a category, see the documentation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pull Most Recent Post Excerpt’ is closed to new replies.