Support » Themes and Templates » Sorting Posts in Alphabetical Order

  • Resolved Matt Hancock


    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; ?>

    Any help would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

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

    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 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sorting Posts in Alphabetical Order’ is closed to new replies.