• Resolved djr3110

    (@djr3110)


    Hi I’m looking for an easy way to have my posts appear in alphabetical order automatically. The archive.php file has this bit of code in it to generate the list

    <div class=”contenttitle”>
    <h1>” rel=”bookmark”><?php the_title(); ?></h1>

    So I all I want to do is sort be title – which I assume is ther php the_the bit.

    Any help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Add this code before your Loop.

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

    Thread Starter djr3110

    (@djr3110)

    OK I’m being thick here I’m sure but I don’t understand! I’ve read about the loop but it’s not clear to me – sorry

    The code I have in my archive.php is

    <?php get_header(); ?>

    <div id=”content”>

    <?php include(TEMPLATEPATH.”/sidebar.php”);?>

    <div id=”contentmiddle”>

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

    <div class=”contenttitle”>
    <h1>” rel=”bookmark”><?php the_title(); ?></h1>
    <p>Filed Under <?php the_category(‘, ‘) ?> | <?php comments_popup_link(‘Leave a Comment’, ‘1 Comment’, ‘% Comments’); ?></p>
    </div>

    $query_string.”&orderby=title&order=ASC”

    <!–
    <?php trackback_rdf(); ?>
    –>

    <?php endwhile; else: ?>

    <p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p><?php endif; ?>
    <p><?php posts_nav_link(‘ — ‘, __(‘← Previous Page’), __(‘Next Page →’)); ?></p>
    </div>

    </div>

    <!– The main column ends –>

    <?php get_footer(); ?>

    That’s it I but where should I put the code you suggested?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You put it before the Loop.

    Your Loop starts with this line:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    So add this right before that:
    <?php query_posts($query_string."&orderby=title&order=ASC"); ?>

    Thread Starter djr3110

    (@djr3110)

    You are a star!!!

    That is the first time I have understood the loop – now lots more makes so much more sense.

    Thank you, it works! Have a good weekend

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post sort order’ is closed to new replies.