WordPress.org

Support

Support » How-To and Troubleshooting » Reverse order of posts in a category

Reverse order of posts in a category

  • doctorb
    Member

    @doctorb

    Hi,

    By default posts in a category are shown in the descending order by date. That is what you post last is shown first on the category page.

    I need to reverse this order ONLY in one category of my site. Reason – publishing an e-book section on the site. We start posting the books like – preface, introduction, page1, page2, page3… and so on.

    The category index shows:

    pagen
    .
    .
    page3
    page2
    pag1
    introduction
    preface

    I would like it to come up as

    preface
    introduction
    page1
    page2

    and so on.

    I do not want to touch the general sort order as rest of the site has articles which should come up in the default sort order. I need to alter the sort order for just one category. How can I do this?

    Your help would be much appreciated.
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • doc4
    Member

    @doc4

    doctorb,

    Here is one option:

    query_posts('showposts=5&order=DESC');
    if ( have_posts() ) : while ( have_posts() ) : the_post();

    Order Parameters:
    Designates the ascending or descending order of the ORDERBY parameter.

    * order=ASC – ascending order, lowest to highest value
    * order=DESC – descending order, highest to lowest value

    For more information look through the codex here: http://codex.wordpress.org/Template_Tags/query_posts

    doctorb
    Member

    @doctorb

    Thanks for your reply. I solve dthis by adding:

    <?php if (is_category(array(56,57))){
    query_posts($query_string . “&order=ASC”);} ?>

    Before this line
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    One can add the number of categories in the array of which they want to reverse the post order.

    MattSimpson
    Member

    @mattsimpson

    Why not just artificially set the dates of subsequent postings to be further back in time?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Reverse order of posts in a category’ is closed to new replies.