WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display post titles from a single category (2 posts)

  1. Storyman
    Member
    Posted 6 years ago #

    The goal is to have only the article titles of a particular category display in a list on the sidebar.

    I've been able to accomplish this by creating a sub-category with the same name as the title for every post. That creates a lot of sub-categories.

    It seems that a cleaner, simpler approach would be to display only the post titles for a specific category. After digging through previous post and the WordPress documents I've been unable to figure it out. I'm sure that I've overlooked something simple.

    How to display only the post titles for a particular category? --and not the category title itself!

  2. cregy
    Member
    Posted 6 years ago #

    Try this:

    <?php if ( is_category('3') ) : ?>
    <li>
    <h2>News</h2>
    <ul>
    <?php
    $posts = get_posts('numberposts=10&category=3&orderby=post_title&order=ASC');
    foreach($posts as $post) :
    ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>
    </li>
    <?php endif ; ?>

    Rich

Topic Closed

This topic has been closed to new replies.

About this Topic