How to sort Archives alphabetically ? (6 posts)

  1. cluepatel
    Posted 6 years ago #

    hello guyz,

    i need help regarding archives. i ssw somewhere on internet that we can show archives as alphabetic order. means archieve with A will show all post whose title will start from A. archive B will show all the posts with title starting from B.

    please help me in detail. i wanna construct archieve like that.

    thanks in advance...

  2. @mercime
    Volunteer Moderator
    Posted 6 years ago #

  3. MichaelH
    Posted 6 years ago #

    As an example, using the WordPress Default theme, edit wp-content/themes/default/archive.php and right before this line:

    <?php while (have_posts()) : the_post(); ?>

    add this:

    query_posts($query_string . '&orderby=title&order=ASC');

    For elaborate indexes, look for the plugin AZIndex.

  4. Mark / t31os

    Posted 6 years ago #

    You can query based on the first letter by modifying the where filter example on the query_posts page..

    This is very basic example, and most certainly could be improved.

    My first go at modifying the WHERE filter though, i was quite happy how easy it was.. :)


    <?php if (have_posts()) : ?>

    Place the following code.

    function filter_where($where = '') {
    	$a_z = range('a','z');
    	if(isset($_GET['starts_with']) && in_array($_GET['starts_with'],$a_z)) {
    		$where .= " AND post_title LIKE '$_GET[starts_with]%'";
    	else {
    		$where .= " AND post_title LIKE '%'";
    	return $where;
    add_filter('posts_where', 'filter_where');

    Tested in the theme archive.php, and made up in a few mins, so as said, proberly could do with a little improvement...

  5. northernwolf
    Posted 6 years ago #

    Be careful of the AZ-Index, no one is maintaining it and it doesn't work above 2.7.1

  6. MichaelH
    Posted 6 years ago #

    northernwolf - I was able to install azindex at 2.8.4 and it worked.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.