Support » Themes and Templates » need 3 divs displaying 3 post categories on home page

  • http://www.joshjelsing.com

    The home page needs to display 3 divs that display the latest post in their respective categories.

    Left Sidebar
    Main Content
    Bottom Sidebar.

    I left colored borders around each div for you to see the areas.

    I need the PHP code to display only 1 category (with 2 newest posts) in each div.

    Also, do I add this code to the homepage.php template file I created?
    Ideally, I thought I could have this template file have all 3 divs with each displaying their appropriate categories.

Viewing 1 replies (of 1 total)
  • http://codex.wordpress.org/Class_Reference/WP_Query

    example:

    <?php $left_cat_id = 17; //enter the category id here
    $left_query = new WP_Query( array( 'category__in' => array($left_cat_id), 'posts_per_page' => 2 ) );
    if( $left_query->have_posts() ) : while( $left_query->have_posts() ) : $left_query->the_post();
    /*YOUR OUTPUT HERE*/
    endwhile;
    else : echo 'no posts for cat' . get_category($left_cat_id)->name;
    endif;
    ?>

    same for $main_query and $bottom_query (change the variable names to your choice).

    (untested)

Viewing 1 replies (of 1 total)
  • The topic ‘need 3 divs displaying 3 post categories on home page’ is closed to new replies.