WordPress.org

Ready to get started?Download WordPress

Forums

Reverse order of posts in a category (4 posts)

  1. doctorb
    Member
    Posted 4 years ago #

    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!

  2. doc4
    Member
    Posted 4 years ago #

    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

  3. doctorb
    Member
    Posted 4 years ago #

    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.

  4. MattSimpson
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic