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

  1. Storyman
    Posted 7 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
    Posted 7 years ago #

    Try this:

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


Topic Closed

This topic has been closed to new replies.

About this Topic