WordPress.org

Ready to get started?Download WordPress

Forums

Category and it's posts in the sidebar (2 posts)

  1. zapata
    Member
    Posted 8 years ago #

    Just moved to WP 2.0 and loving it, still trying to crawl over it's learning curve.

    I have 7 categories listed in the sidebar. I want to create a seperate section in the side bar for 2 of these 7 categories. This section will display the category name and all the posts under this category.

    Would appreciate any help/leads on this. Thanks!

  2. MichaelH
    Member
    Posted 8 years ago #

    This example, stolen from alphaoide's excellent example, will list the Category Description for Category 2, then list the five (5) most recent posts from Category 2, then do the same thing for Category 1.

    <?php echo category_description(2); ?>

    <?php
    $posts = get_posts("category=2&numberposts=5");
    if( $posts ) :
    ?>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    <?php echo category_description(1); ?>

    <?php
    $posts = get_posts("category=1&numberposts=5");
    if( $posts ) :
    ?>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    Of course, this goes in your sidebar.php file!
    ********************
    Welcome to the WordPress Support Forums!

    Please help keep the Forums successful by reading:
    Using the Support Forums

    Also, remember the WordPress Codex and the FAQ pages.

    And, thank you, for letting us know if this information proves useful (or not)!
    ********************

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags