Title: Loop sorting
Last modified: August 18, 2016

---

# Loop sorting

 *  [propnut](https://wordpress.org/support/users/propnut/)
 * (@propnut)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/)
 * Where I can find some info how to display all posts sorted backwards? The newest
   post will be on the end of the loop and the oldest on top.
    George

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [eston](https://wordpress.org/support/users/eston/)
 * (@eston)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/#post-344682)
 * You’ll want to use `query_posts` to re-order the loop to `ASC` (ascending) rather
   than the default `DESC` (descending.) Before your Loop, add this line:
 * `<?php query_posts('order=asc'); ?>`
 * and the `query_posts` function will re-query the loop to order in ascending order.
   Here’s an example of a modified version of Kubrick’s index:
 * `
    <?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()):?
   > <?php query_posts('order=asc'); while (have_posts()) : the_post(); ?>
 *  [hama](https://wordpress.org/support/users/hama/)
 * (@hama)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/#post-344704)
 * I think I don’t understand “loop” correctly. I tried to build in your piece of
   code and then I get a parse error on the last line. Can’t understand why. his
   is my a litte bit modified index. Where should I build in your code? Thanks for
   a little bit help. hama
 * <body>
    <div id=”rap”> <?php get_header(); ?> <div id=”main”> <div id=”content”
   > <div class=”post”> <div class=”post-info”><h2 class=”post-title”>Willkommen
   </h2></div> <div class=”post-content”>
 *  <img src=”index/index.jpg” alt=”Sybi” class=”teaser” />
    Text comes soon.
 *  <div class=”post-footer”> </div>
    </div> </div> </div> <div id=”sidebar”> <h2
   ><label for=”s”><?php _e(‘Search:’); ?></label></h2>
    -  <form id=”searchform” method=”get” action=”<?php echo $_SERVER[‘PHP_SELF’];?
      >”>
       <div style=”text-align:center”> <input type=”text” name=”s” id=”s” size
      =”15″ /> <input type=”submit” name=”submit” value=”<?php _e(‘Search’); ?>”/
      > </div> </form>
 *  <h2><?php _e(‘Categories:’); ?></h2>
    - <?php wp_list_cats(‘optioncount=1’); ?>
 *  </div>
 * <?php get_footer(); ?>
    </div> </div> </body>
 *  [hama](https://wordpress.org/support/users/hama/)
 * (@hama)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/#post-344705)
 * I solved the problem. My startpage is static so I had to build in
 * <?php query_posts(‘order=asc’);
 * into category.php. It works. 🙂
 * Have a good time
 * hama
 *  [hama](https://wordpress.org/support/users/hama/)
 * (@hama)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/#post-344718)
 * It didn’t work! My solution to build in the code into category.php is wrong!
 * In one category it worked, in another one not and in monthly view it didn’t work.
 * Maybe someone can help me again and show me how to include ” ascending ” in every
   category and in monthly view. I modified index.php because I want a static frontpage.
 * Thanks and have a nice evening!
 * hama

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Loop sorting’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [hama](https://wordpress.org/support/users/hama/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/loop-sorting/#post-344718)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
