Support » Developing with WordPress » excerpt in mini-loop

  • superted

    (@superted)


    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.

    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘excerpt in mini-loop’ is closed to new replies.