WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for plugin to sort posts by alphabetic orders.

Sort: A-Z Z-A Newest Oldest

and option to view per page like in stake exchange websites

Per Page: 20 40 60 All

if not exists, can i do this in query post(How ?) Please suggest me !


share|improve this question
up vote 1 down vote accepted

Don't know about a plugin but you can do that easily with query_posts()

paste this two functions in your theme's functions.php file

function display_sort_links(){
    <div class="sort_links">
            <li><a href="?P_O=az">A - Z</a></li>
            <li><a href="?P_O=za">Z - A</a></li>

function display_posts_numbers(){
    <div class="number_links">
            <li><a href="?P_P=20">20</a></li>
            <li><a href="?P_P=40">40</a></li>
            <li><a href="?P_P=60">60</a></li>
            <li><a href="?P_P=-1">All</a></li>

then paste this in the archive file just above you loop (if have_posts())

global $query_string;
parse_str( $query_string, $args );
//check for posts number per page
if (isset($_GET['P_P'])){
    $args['posts_per_page'] = (int)$_GET['P_P'];
//check for posts order a-z or z-a
if (isset($_GET['P_O'])){
    switch ($_GET['P_O'])){
        case "az":
            $args['orderby'] = 'title';
            $args['order'] = 'ASC';
        case "za":
            $args['orderby'] = 'title';
            $args['order'] = 'DESC' ;

query_posts( $args );

and where ever you want the links to show just call the functions from before :

//for a-z z-a sort use:
<?php display_sort_links(); ?>

//and for numbers use:
<?php display_posts_numbers(); ?>
share|improve this answer
many thanks, You helped me lot. Thanks again – Gowri Jun 24 '11 at 4:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.