WordPress.org

Ready to get started?Download WordPress

Forums

Reverse order posting (19 posts)

  1. wiredkiwis
    Member
    Posted 9 years ago #

    Can this be done in WP?
    I have a blog set to posts paged but I want the posts to show the oldest first.
    Have hunted but cannot find a mention of it.
    Anyone like to point me in the right direction?

  2. Joshua Sigar
    Member
    Posted 9 years ago #

  3. Mark (podz)
    Support Maven
    Posted 9 years ago #

    Reverse order posts:
    http://wordpress.org/support/3/15749
    This is from the first post ever, not the first post of the day.

  4. TechGnome
    Moderator
    Posted 9 years ago #

    Open wp-blog-header.php
    Look for this line:

    $where .= $search.$whichcat.$whichauthor;
    if ((empty($order)) || ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) {
    $order='DESC';
    }

    It will be a little more than half way down.
    Add the following right after that.
    If you want to change the order on some categories, try this:

    if ('11' == $cat) {
    $order='ASC';
    }

    Changing the 11 to any cat you want.
    If you want to change the order for all posts in all categories then remove the first & third lines of the above code.
    If you check out my site, you'll see that most of the site is ordered normaly - newer first. But any of the sections under Writtings & Scribblings are ordered Oldest first.
    TG

  5. wiredkiwis
    Member
    Posted 9 years ago #

    Sorted..Thanks all
    as stated by the above posts on about line 680'ish in wp-blog-header.php:
    $order='DESC'; changed to $order='ASC';
    Damn that was easy :)
    :another happy wp user:

  6. Cornwell
    Member
    Posted 9 years ago #

    In version 1.5 (just installed) the code isn't in wp-blog-header.php but I found it in wp-includes/classes.php on line 460.

    I can get it to change the order on all categories, simply by changing 'DESC' to 'ASC' but the change to some categories doesn't seem to work, presumably because the variable isn't called $cat any more?

    Roger Cornwell

  7. Cornwell
    Member
    Posted 9 years ago #

    Well, a lack of responses to my post (above) led me to investigate further. And it seems to be surprisingly simple. In the example above, instead of

    if ('11' == $cat) {
    $order='ASC';
    }

    you need to code

    if ('11' == $q['cat']) {
    $q['order']='DESC';
    }

    Roger

  8. dannyman
    Member
    Posted 9 years ago #

    Hi.

    Here is how to RECURSIVELY reverse-order a group of categories, by hacking .htaccess.

    Compare:
    http://dannyman.toldme.com/category/technology/

    Contrast:
    http://dannyman.toldme.com/category/world-tour/
    http://dannyman.toldme.com/category/world-tour/jordan/

    Okay, howto?

    In my .htaccess, I put this:
    RewriteRule ^category/(world-tour.+)/?$ /index.php?category_name=$1&order=ASC [QSA,L]

    Right before this line:
    RewriteRule ^category/(.+)/?$ /index.php?category_name=$1 [QSA,L]

    Ditto for chronological archives:
    RewriteRule ^(archive)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2&order=ASC [QSA,L]

  9. dannyman
    Member
    Posted 9 years ago #

    I recently added paged category archive posting. I realized things eren't working quite right, so now my .htaccess has been amended:

    # Reverse-Order pages within world-tour/
    RewriteRule ^category/(world-tour.*)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2&order=ASC [QSA,L]
    RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L]
    # Reverse-Order pages within world-tour/
    RewriteRule ^category/(world-tour.*)/?$ /index.php?category_name=$1&order=ASC [QSA,L]
    RewriteRule ^category/(.+)/?$ /index.php?category_name=$1 [QSA,L]

  10. rgkeir
    Member
    Posted 9 years ago #

    This is why I love WP. I just decided I needed to reverse order
    posts in some categories and it took me all of about 2 minutes
    to find 2 different solutions.

    Thank you all - the forums are terrific and WP rocks.

  11. damino
    Member
    Posted 8 years ago #

    Thank you to Cornwell : that is the solution !
    Just a note : use 'ASC' instead of 'DESC', if not the code is added for nothing !!!

  12. nieuws
    Member
    Posted 8 years ago #

    ASC will do the job indeed. You can also try and write your own function. Fairly easy even without PHP knowledge.

  13. stonegauge
    Member
    Posted 8 years ago #

    How woudl I accomplish this in WP 2.0? I want to chronologically list my archives (probably specifically)...

  14. There is no need to be editing core files or rewrite rules here people.

    Just use this right above your Loop:

    http://codex.wordpress.org/Template_Tags/get_posts

    See also (same kinda thing, but this example sorts by title rather than date):

    http://codex.wordpress.org/Alphabetizing_Posts

  15. Ferientechniker
    Member
    Posted 8 years ago #

    The correct code for wp2.01 is:
    (wp-includes/classes.php)

    after:
    if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) {
    $q['order']='DESC';
    }

    type: (change 23 to your category number)

    if ('23' == ($q['cat'])) {
    $q['order']='ASC';
    }

  16. jabash
    Member
    Posted 8 years ago #

    How would this be done by a a user selection?

  17. stairway
    Member
    Posted 8 years ago #

    I had the same problem but found the solution here: http://codex.wordpress.org/Template_Tags/query_posts

    There is no need to change any core files. Just insert this code right above your loop, and change the variables to suit your needs.


    $categoryvariable=$cat; // assign the variable as current category
    $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC'; // concatenate the query
    query_posts($query); // run the query

    works perfectly every time.

  18. VeronicaRose
    Member
    Posted 8 years ago #

    <?php
    $categoryvariable=$cat; // assign the variable as current category
    $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC'; // concatenate the query
    query_posts($query); // run the query
    ?>

    When I look at this I don't understand which part I'm supposed to replace with the title of the category that I want changed. Can someone please help me?

  19. zannmarketing
    Member
    Posted 8 years ago #

    stairway, thanks for pointing me to the right direction! The code you have posted doesn't behave with paging. That is, I couldn't get posts 11-20 to show up on page 2.

    My solution is to add this code above The Loop:

    query_posts($query_string."&order=ASC");

    This will make all of the posts in all of your categories ordered to show the oldest post first and the newest post last.

    To reverse order of posts in only one category use this:

    <?php if ($cat==x) {query_posts($query_string."&order=ASC"); } ?>

    Where x in $cat=x is the category ID number.

    Note: if you still don't know what The Loop is, it starts with this line:

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

    The query_post should be ABOVE this line.

Topic Closed

This topic has been closed to new replies.

About this Topic