WordPress.org

Ready to get started?Download WordPress

Forums

Show Posts if is_front_page (2 posts)

  1. tannerhobin
    Member
    Posted 5 years ago #

    I've set a static page as my front page. I'm trying to show the 2 latest posts on that page. I've got the code working to insert the 2 posts, but I need to some how enclose that code in an is_front_page statement.

    Here's my code for page.php:

    <?php $postslist = get_posts('numberposts=2&order=ASC'); foreach ($postslist as $post) : setup_postdata($post); ?>
        <div>
    	<?php the_title(); ?><br />
            <?php the_date(); ?><br />
            <?php the_excerpt(); ?>
        </div>
    <?php endforeach; ?>
  2. seriocomic
    Member
    Posted 5 years ago #

    From: http://codex.wordpress.org/Conditional_Tags#The_Front_Page

    Wouldn't wrapping it in another if statement work?

    <?php if (is_front_page()):
    $postslist = get_posts('numberposts=2&order=ASC');
    foreach ($postslist as $post) : setup_postdata($post); ?>
        <div>
    	<?php the_title(); ?><br />
            <?php the_date(); ?><br />
            <?php the_excerpt(); ?>
        </div>
    <?php endforeach;
    endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic