[resolved] Post sort order (5 posts)

  1. djr3110
    Posted 7 years ago #

    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?

  2. Add this code before your Loop.


  3. djr3110
    Posted 7 years ago #

    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>


    <?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>


    <!-- The main column ends -->

    <?php get_footer(); ?>

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

  4. 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"); ?>

  5. djr3110
    Posted 7 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic