Organize posts by Category in Home Page?

Discussion in 'HTML & Website Design' started by TheCarlisle, Mar 28, 2011.

  1. #1
    Hi, I'm currently working on a custom theme and was wondering how I can create a home page with distinct category sections (simply separating posts by category) like in this theme: http://demo.wpzoom.com/?theme=magnific

    Is there a specific tidbit of PHP I have to include in the homepage, or is there some call I have to enter? I'd just like to separate the posts by category. From there, I think I can tinker my way around and create the rest of the theme. Any input would be greatly appreciated :)
     
    TheCarlisle, Mar 28, 2011 IP
  2. extremike

    extremike Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Assuming you're using Wordpress? You need to add a post query before your loop like so:

    <!-- POST QUERY -->
    <?php query_posts($query_string . '&cat=13'); ?> 
    <!-- change cat=13 to the category to be displayed -->
    
    <!-- THE LOOP -->
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- YOUR STUFF -->         
    <?php endwhile; else: ?>
    <?php endif; ?>
    <!-- LOOP ENDS -->
    Code (markup):
    Further reading here: http://codex.wordpress.org/Function_Reference/query_posts
     
    extremike, Mar 29, 2011 IP
  3. TheCarlisle

    TheCarlisle Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you!!! That's exactly what I was searching for :D
     
    TheCarlisle, Mar 29, 2011 IP