excerpt in mini-loop (2 posts)

  1. superted
    Posted 8 years ago #

    I have a blog with a static front page that I want to show excerpts from recent posts. I have a second page (/success-stories) with the same basic feature.

    If I use a mini loop that basically copies The Loop:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>...

    then it messes up a custom nav element I have in my sidebar because the counter seems to affect the is_page() function and my nav element can't tell what page it is on.

    If I use a mini loop with a custom call to the db:

    $news=$wpdb->get_results("SELECT ID,post_title,post_date,post_excerpt FROM $wpdb->posts
    WHERE post_type='post' AND post_status='publish' ORDER BY 'ID' DESC LIMIT $how_many");
    foreach($news as $np){...

    then I can't seem to pull post_excerpt and display it on the page.

    echo $np->post_excerpt; // i tried this line with the "printf" version of the mini-loop
    echo apply_filters('the_excerpt', $np->post_excerpt); // and then this line just to test it out!

    For now I'll just be displaying the title and date of the most recent posts. If you have some insight into this, please let me know.

    BTW, there are lots of questions about this in the support forum and none that I have found seem to work without being in the loop.

    http://powermyhealth.com/ to check out the site I'm working on.


  2. Kafkaesqui

    Posted 8 years ago #


    See the section specifically on using WP_Query() to create a new query object (rather than using query_posts(), which I assume you meant above when you mentioned copying The Loop).

    Similar issue discussed recently here:


Topic Closed

This topic has been closed to new replies.

About this Topic