WordPress.org

Forums

[resolved] Sorting Posts in Alphabetical Order (3 posts)

  1. Matt Hancock
    Member
    Posted 4 years ago #

    So I have this query which lists all the posts by category on a sidebar. I want to expand it slightly so that it lists the posts in alphabetical order.

    Code is as follows:

    <ul class="sidebar">
    <?php $recent = new WP_Query("cat=3&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    Any help would be appreciated.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    <?php $recent = new WP_Query("cat=3&posts_per_page=10&orderby=title");

  3. Matt Hancock
    Member
    Posted 4 years ago #

    Just had to modify it slightly to get the order correct:

    <?php $recent = new WP_Query("cat=3&posts_per_page=20&orderby=title&order=asc");

    Cheers :)

Topic Closed

This topic has been closed to new replies.

About this Topic