• Resolved mollylovesmacs

    (@mollylovesmacs)


    Hello all,

    We have a client site that required the main blog posts to be listed in ascending order. We found handy solution over at WordPress Experiments – ‘Custom order of posts on main page‘, and used the following code to achieve this:

    <?php $posts=query_posts($query_string . '&order=asc');
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    However we have just discovered that the categories (posts) are still listed in descending order.

    I’ve had a scan of the WP forums before posting but some solutions appear to be theme dependent. Can someone point me to a definitive solution?

    Thanks in advance
    Molly

Viewing 5 replies - 1 through 5 (of 5 total)
  • With the help of the Template Hierarchy article, determine what Template is displaying your category archives (could be category.php or archive.php). Then edit that Template and add the same code you did to your index.php.

    Thread Starter mollylovesmacs

    (@mollylovesmacs)

    Hello Michael,

    Thanks for the information.
    I’ve had a read of the links you kindly provided and have found that the file I need to modify is indeed archive.php. I traced the identical line of code within archive.php as I had in the original (unmodified) index.php file:

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

    ..and replaced this with the new code that gives me ascending post order in the blog page:

    <?php $posts=query_posts($query_string . '&order=asc');
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    However, when I go to view the pages I get the following error:

    Parse error: syntax error, unexpected $end in /home/walletsm/public_html/wp-content/themes/walletsmarts/archive.php on line 186

    I would appreciate any further pointers you can give me.

    Molly

    This line is not identical

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

    to

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

    go back and check that

    Thread Starter mollylovesmacs

    (@mollylovesmacs)

    I’ve just checked – you’re correct, the line of code is different (I’m just getting my ‘newbie’ head around PHP which might explain it!)

    OK, (and just so that I can get my head around it) on my index.php page I had the following two lines of code:

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

    I replaced both with:

    <?php $posts=query_posts($query_string . '&order=asc');
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    Which gave me ascending post order.

    On my archive.php page I only have the second (albeit identical) line of code as that on the original index.php page:

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

    Don’t laugh, but I thought that I could just replace this single line (as I did in the index.php page) with the same ascending order code. Obviously not. ;o)

    The following appears to work (Hooray!) though I wonder if you could cast your expert eye over the syntax for me just to confirm.

    <?php $posts=query_posts($query_string . '&order=asc');
    while (have_posts()) : the_post(); ?>

    Thanks for taking the time; appreciated.
    Molly

    Looks fine. Thanks for the feedback. Will mark this resolved.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘sorting category posts differently (ascending order)’ is closed to new replies.