sort posts by alphabetic plugin suggestion

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

Read More
Per Page: 20 40 60 All

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

Thanks

Related posts

Leave a Reply

1 comment

  1. 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(); ?>