• jdsnia

    (@jdsnia)


    I’m using the static home page plugin for a homepage that is part of the wordpress blog, but doesn’t list any of the blog posts.

    I’d like the blog entries to be listed in the /blog directory as they normally would be listed on the main page.

    I’ve looked in the codex and seen code that kind of almost skirts around what I’m looking for.

    If I create a blog page, can I assign it a custom template that consists soley of a loop that will list the last X number of posts/post excerpts?

    Thanks for the help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • bpartch

    (@bpartch)

    Mark Bloomfield

    (@yellowllama)

    Yup, its quite simple: on a wordpress page/template, put this where you want your posts to display:

    <?php $posts = get_posts(''); foreach($posts as $post) : ?>
    <h2><a href= "<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>

    that’ll output a list of posts with the title of the article being an <h2> and then an excerpt of the article.

    the arguments you could use for the query could set the number of posts, the category you wish to display posts from (default is all categories). for example, to display only 1 recent post, the first line above, would change to:

    <?php $posts = get_posts('numberposts=1'); foreach($posts as $post) : ?>

    if you wanted 10 posts from the category with the id of 3, you’d say:

    <?php $posts = get_posts('numberposts=10&category=3'); foreach($posts as $post) : ?>

    etc.etc…

    hope that helps 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘List recent posts on a page’ is closed to new replies.