WordPress.org

Ready to get started?Download WordPress

Forums

Spun
Posts in ascending order (8 posts)

  1. timovinyl
    Member
    Posted 1 year ago #

    Hello,

    I am using the SPUN theme and loving it.

    I have modified the look and created a new category.php to display posts in my categories.

    On the startpage (index.php) and on the categories (category.php) I would like to order my posts by the date BUT in ascending order.

    I have googled this problem and found many results and solutions. Mostly mentioned is it to add a line before the loop, exactly before

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

    The line that user should add is this:

    <?php query_posts($query_string . '&orderby=date&order=ASC'); ?>

    Fine. The problem is: Nothing changes - the posts are still in descending order!

    I assume that this might be a problem with the SPUN theme, that's why I am writing here.

    I really really hope that you can help me because displaying posts in the ascending order is absolute essential to my wordpress project and I wouldn't like to use another theme than SPUN just because this change of order won't work.

    Thanks SO much in advance!

  2. Caroline Moore
    Member
    Theme Author

    Posted 1 year ago #

    It's not likely a problem with the Spun theme, since Spun doesn't modify The Loop.

    The best way to test this is to apply the same code to one of the default themes, like Twenty Twelve -- if it still doesn't work, it's a problem with your code, not the theme.

    In general, it's better practice to use WP_Query to modify The Loop, rather than query_posts.

  3. timovinyl
    Member
    Posted 1 year ago #

    Caroline, thanks for your reply!

    I tested it with twentyeleven and it worked. Then I copied the category.php from twentyeleven to my spun directory and there it didn't work. That is why I assumed it was a problem with the theme.

  4. Caroline Moore
    Member
    Theme Author

    Posted 1 year ago #

    I did a quick test and copied the same code into Spun's archive.php, and it worked.

    Are you working in a child theme by chance?

    If so, copying category.php into your child theme might not work because there's no category.php template in the parent theme to match it.

    Spun uses archive.php to handle categories, tags, and other archives. Try copying Spun's archive.php into your child theme, then apply the code (although again, I'd modify it to use WP_Query -- here's a good explanation of why and how.)

    Copying a template file from one theme into an entirely different theme is probably not a good practice in general -- if you intend to target the archives with category.php, for example, copy from the code in Spun's archive.php to generate the categories, such that it retains the same CSS classes, functions, and behavior.

    That's the only reason I can think it wouldn't work across themes. Again, Spun doesn't touch or modify The Loop in any way -- just outputs whatever WordPress pulls by default. I'm betting it's a mismatch in the parent/child theme template hierarchy.

  5. timovinyl
    Member
    Posted 1 year ago #

    Thanks for your reply.

    As far as I know (I am more of a beginner to be honest) I am not using a child-theme. I just installed SPUN and use it like this.

    Okay, so I will use the archive.php and delete the category.php again.

    Maybe the problem is something about how I display the posts in the loop itself.

    I will try to recover the archive.php, add the query to change the order and then step by step change the way the loop prints out the posts.

  6. Caroline Moore
    Member
    Theme Author

    Posted 1 year ago #

    Definitely use a child theme for modifications like this -- if you need to update the theme in the future, your changes could get wiped out, which would suck. You'll find info about how to set up a child theme in the link I posted above.

  7. timovinyl
    Member
    Posted 1 year ago #

    I just restored the original archive.php from the SPUN theme and JUST added the line:

    <?php query_posts($query_string. "&order=ASC"); ?>

    It does not work. What am I doing wrong?

    I'm not able to create a query with wp_query - I know too little about PHP and wordpress and don't get the codex unfortunately.

  8. Caroline Moore
    Member
    Theme Author

    Posted 1 year ago #

    I couldn't say, since I can't see where you've placed it in relation to the rest of the code. You might try asking the original creator of that snippet for assistance.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic