• Resolved yogidevotee

    (@yogidevotee)


    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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tubal

    (@tubal)

    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' );
    ?>

    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?

    Plugin Author Tubal

    (@tubal)

    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'); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Sort Query Posts] how to reorder category archive posts ONLY’ is closed to new replies.