Forums

Static home page with latest blog posts (2 posts)

  1. tjobbe
    Member
    Posted 2 years ago #

    Hi Guys,

    I have created a page and set it as my static front page in the options, now I'd also like to add a "simple" conditional statement to my page.php that shows the latest X posts from a particular category on the home page, but only the home page.

    I haven't a clue where to begin with this! I have searched - believe me - but for whatever reason I just can't seem to find exactly what I need.

    Please don't just direct me to the conditional tags section - I've seen it and read it but what I'm really looking for is what code to use on the page to show the latest X posts from Y category if it's the home page.

    Thanks in advance, ANY help appreciated!

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Here is some sample code adapted from the Codex:The Loop/Multiple Loops In Action:

    // going off on my own here
     <?php if ( is_front_page() ) :
       $temp_query = clone $wp_query;
       query_posts('category_name=special_cat&posts_per_page=10');
       while (have_posts()) : the_post(); ?>
          <!-- Do special_cat stuff... -->
       <?php endwhile; ?>
    
       // now back to our regularly scheduled programming
       <?php $wp_query = clone $temp_query;
    endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.