WordPress.org

Ready to get started?Download WordPress

Forums

Sort Query Posts
[resolved] how to reorder category archive posts ONLY (4 posts)

  1. yogidevotee
    Member
    Posted 3 years ago #

    Hello,
    I have a twenty ten theme, and am trying to have the order of posts in the category archives in reverse-chronological order (earliest posts first)
    I want to do this just for category archives and not globally.

    I've been adding <?php sort_query_posts_by('ID', 'desc'); ?> at various places in archives.php but am not getting the desired result.

    Any ideas?

    Thanks!

    http://wordpress.org/extend/plugins/sort-query-posts/

  2. Tubal
    Member
    Plugin Author

    Posted 3 years ago #

    Hi yogidevotee,

    It's really simple, all you have to do is place the function call before any "loop" and pass the function the correct arguments.

    This is part of the code from the file "category.php" from the Twenty Ten theme with posts sorting. Oldest posts will be sorted to appear first.

    <?php
    $category_description = category_description();
    if ( ! empty( $category_description ) )
    	echo '<div class="archive-meta">' . $category_description . '</div>';
    
            // sort the posts BEFORE the loop by date, oldest first (asc)
    	sort_query_posts_by('date', 'asc');
    
    	/* Run the loop for the category page to output the posts.
    	* If you want to overload this in a child theme then include a file
    	* called loop-category.php and that will be used instead.
    	*/
    	get_template_part( 'loop', 'category' );
    ?>
  3. c.hennen
    Member
    Posted 3 years ago #

    This is te code i use in category-txt.php

    <div id="container">
      <div id="content" role="main">
       <ul id="CategoryTekst">
        <?php sort_query_posts_by('title','asc'); ?>
        <?php while ( have_posts() ) : the_post(); ?>
         <li>
          <h5>Code: <?php the_title(); ?></h5>
          <?php the_content(); ?>
         </li>
        <?php endwhile; ?>
       </ul>
      </div><!-- #content -->
     </div><!-- #container -->

    Still (post names are: 00-01-xxxnl > 00-04-xxxnl) the post are not sorted correctly.

    What do i do wrong?

  4. Tubal
    Member
    Plugin Author

    Posted 3 years ago #

    Emmm...if post titles are 00-01-xxxnl, 00-04-xxxnl etc... they are sorted correctly by their title in ascending order (as in your example).

    If you want your posts to be sorted in descending order (00-04-xxxnl, 00-01-xxxnl etc...) use this:

    <?php sort_query_posts_by('title', 'desc'); ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic