WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post sort order (5 posts)

  1. djr3110
    Member
    Posted 6 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. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Add this code before your Loop.

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

  3. djr3110
    Member
    Posted 6 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>
    </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?

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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
    Member
    Posted 6 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