WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Mini-loop - little code tweak help (3 posts)

  1. pcwp
    Member
    Posted 8 years ago #

    I am using the mini-loop on a home page. I want to display the post content.
    Also I would maybe like to display the excerpt instead.
    This code is successful in fetching the latest post and displaying the title. How can I get it to display the content and how could I get it to display the excerpt?
    thanks.

    code:
    <?php
    $how_many=1;
    require_once("/wp-config.php"); ?>

    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT
    ID,post_title FROM $wpdb->posts
    WHERE
    post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("<li><a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a></li>");
    } ?>
    </ul>

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Add post_content and post_excerpt to the SELECT statement, so you're getting those columns. Then add output of $np->post_content to your foreach loop.

  3. pcwp
    Member
    Posted 8 years ago #

    perfect and wonderful -
    thanks Otto

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags