WordPress.org

Support

Support » Themes and Templates » [Resolved] Sorting Posts in Alphabetical Order

[Resolved] Sorting Posts in Alphabetical Order

  • Matt Hancock
    Participant

    @matthancocknz

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi
    Forum Moderator

    @esmi

    Try:

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

    Matt Hancock
    Participant

    @matthancocknz

    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 ‘[Resolved] Sorting Posts in Alphabetical Order’ is closed to new replies.