WordPress.org

Ready to get started?Download WordPress

Forums

Loops - Showing Posts on Static Front Page (2 posts)

  1. neocharles
    Member
    Posted 2 years ago #

    Hopefully someone can help me out (completely over my head here).

    I have a page currently titled "General Information" which is set as the static front page. This page currently contains a few paragraphs of information that I would like to remain on the front page.

    I also have a "Blog Posts" page, which will contain all of the blog posts. The settings for these two have been set under Reading.

    My goal is to have a portion on "General Information" that displays some of the blog posts that have a specific category (ex: "Frontpage Posts") that will be 2-3 of the most recent posts in that category.

    How would I go about adding that, while maintaining the ability to add static content to that front page, and up to date posts from that category...

    Thanks!

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    create a page template http://codex.wordpress.org/Pages#Page_Templates

    possibly using a copy of page.php as starting point;

    after the end of the existing loop ( http://codex.wordpress.org/The_Loop ) create a secondary loop with a custom query;

    example:

    <?php $frontpage_posts = new WP_Query( array( 'posts_per_page' => 3, 'category_name' => 'frontpage-posts' ) );
    if( $frontpage_posts->have_posts() ) :
    /*here possibly a FrontPage Posts title or so ? */
    while( $frontpage_posts->have_posts() ) :
    $frontpage_posts->the_post();
    /*whatever you want to output - possibly copied from the loop of index.php*/
    endwhile;
    else : echo 'no frontpage posts';
    endif; wp_reset_postdata();
    ?>

    http://codex.wordpress.org/Class_Reference/WP_Query
    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic