Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 !

Thanks

share|improve this question
add comment

1 Answer

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">
        <ul>
            <li><a href="?P_O=az">A - Z</a></li>
            <li><a href="?P_O=za">Z - A</a></li>
        </ul>
    </div>
    <?php
}

function display_posts_numbers(){
    ?>
    <div class="number_links">
        <ul>
            <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>
        </ul>
    </div>
    <?php
}

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';
            break;
        case "za":
            $args['orderby'] = 'title';
            $args['order'] = 'DESC' ;
            break;
    }
}

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
add comment

Your Answer

 
discard

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.