WordPress.org

Ready to get started?Download WordPress

Forums

List Category Post Titles (3 posts)

  1. bokinuk
    Member
    Posted 8 years ago #

    After searching high and low I'm going to break down and ask for some help please.

    When I go to a Category page I want to list all the post titles from only that Category on the sidebar. I see solutions where a category number or numbers are included in the argument, but that's too static for my purposes.

    I discovered this code in my searches and it does exactly what I need ... except when a post is in more than one category. A number of things could happen then: i.e. all the blogs post titles are displayed .. etc etc

    Could someone please tell if an argument can be included in this so only the post titles of the category page currently being displayed are shown on the sidebar? Many thx.

    <?php
    $cat = get_the_category();
    $cat = $cat[0];
    $posts = get_posts("category=" . $cat->cat_ID . "&numberposts=5");
    if( $posts ) :
    ?>
    <div class="recent-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>
    </div>
    <?php endif; ?>

  2. bokinuk
    Member
    Posted 8 years ago #

    I think I've got the answer. It's in this post this post. No a 100%, but I should be able to work it out.

  3. bokinuk
    Member
    Posted 8 years ago #

    Fraid not. Will continue this in above linked post.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags