WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List of post excerpts to the page (9 posts)

  1. crowd
    Member
    Posted 2 years ago #

    I would like to place the list of my recent posts on one of my static pages. It should go after the main text and show excerpts of the 5 latest posts.
    Could anyone help me with that?

  2. esmi
    Forum Moderator
    Posted 2 years ago #

  3. crowd
    Member
    Posted 2 years ago #

    Esmi, your help is appreciated, but my terminal dullness keeps me from understanding any of your answers. If i were a php guru, i would probably save your time by never posting questions like above.

    So, let me show what i really have trouble with:
    I obviously need to put this multiple loop code somewhere into my index.php or content-page.php (cause it's for the pages, right?)
    This code should read smth like:

    <?php if (it's the 2nd paragraph of the needed page()) : ?>
    <?php while (it's the 2nd paragraph of the needed page()) : it's the 2nd paragraph of the needed page(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    That's my best i can make out of it.
    I don't know how to make it work, i truly have no idea how to make the excerpt appear in the right place. And i really know very little of php to make the right conclusions of the vague answers. My bad, but if i were any smarter, i would find the answer myself.

    And yes - i truly admire your knowledge and appreciate your time trying to help desperados like me.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    What theme are you using?

  5. crowd
    Member
    Posted 2 years ago #

    Im using the child of 2011

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    You need to create a custom page template in your child theme and add the secondary loop code to this new template. Start by copying the code from the parent's page.php template file, then add the secondary query to suit your needs. something like:

    <?php
    $args = array( 'numberposts' => 5 );
    $recentposts = get_posts( $args );
    if( $recentposts ) echo '<ul class="recent-posts">';
    foreach($recentposts as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php endforeach;
    if( $recentposts ) echo '</ul>';?>

    should work.

  7. crowd
    Member
    Posted 2 years ago #

    Esmi, thanks a lot. That's what i needed. Will do.

  8. crowd
    Member
    Posted 2 years ago #

    Esmi, thank you so much, it works like a charming charm!
    And be sure, i would never get any close to this myself.

  9. esmi
    Forum Moderator
    Posted 2 years ago #

    Glad I could help :-)

Topic Closed

This topic has been closed to new replies.

About this Topic