WordPress.org

Support

Support » Themes and Templates » [Resolved] Displaying Multiple Catagories on One Page (In different Sections)

[Resolved] Displaying Multiple Catagories on One Page (In different Sections)

  • Hi,

    On my home page I would like to be able to display posts from different catagories in different areas of the page.

    To make my self clear – in one DIV I want posts from lets say category number 3, and in another DIV I want posts from lets say category number1 1.

    So far I have –
    code
    <?php query_posts( ‘posts_per_page=8′,’category_name=Case-Studies’ ); ?><?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?> …
    /code
    and
    code
    <?php query_posts( ‘posts_per_page=1′,’category_name=Home’ ); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    /code
    but the problem is that both parts display posts from only the Case_Studies category. Ive tried
    code
    <?php query_posts( ‘posts_per_page=1′,’cat=-3’ ); ?>
    /code
    as well to see if i could exclude the 3rd category but it didnt help. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I do the same thing in my sidebar. Here’s how:

    <div id="sidebar">

    <?php
    $posts = get_posts("category=2" . "&numberposts=5");
    if( $posts ) :
    ?>

    <div class="recent-posts">

    <h4><a href="index.php?cat=2">Recent News &raquo;</a></h4>

    <ul>

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <?php
    $even_odd = ( 'odd' != $even_odd ) ? 'odd' : '';
    ?>
    <li class="<?php echo $even_odd; ?>"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    </ul>

    </div>

    <?php endif; ?>

    <?php
    $posts = get_posts("category=3" . "&numberposts=5");
    if( $posts ) :
    ?>

    <div class="recent-posts">

    <h4><a href="index.php?cat=3">Recent Events &raquo;</a></h4>

    <ul>

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <?php
    $even_odd = ( 'odd' != $even_odd ) ? 'odd' : '';
    ?>
    <li class="<?php echo $even_odd; ?>"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    </ul>

    </div>

    <?php endif; ?>

    <h4><a href="?page_id=31">Links &raquo;</a></h4>
    <ul>
    <?php get_links('1', '<li>', '</li>', ' ', FALSE, 'rating', TRUE, TRUE, 15, TRUE); ?>
    </ul>

    </div>

    The bits about $even_odd are from http://markjaquith.wordpress.com/2006/06/20/alternating-rows-in-php/
    It gives the <li> element an alternating clas of “odd” so as to style them with stripes or however you’d like.

    Ok thanks I’ll give it a try right now

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Displaying Multiple Catagories on One Page (In different Sections)’ is closed to new replies.