Reverse Post Order for Single Category

Community Forums Forums Design Tips and Tricks Reverse Post Order for Single Category

This topic is: not resolved

Tagged: 

This topic contains 7 replies, has 5 voices, and was last updated by  jodzeee 4 weeks ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #55465

    scallemang
    Participant
    Post count: 4

    Hi there,

    I’m looking for a way to print one of my categories in ascending chronological order while leaving all others descending.

    I’m only just starting out with PHP, so forgive any goofy errors. I found the following code somewhere online (the category in question is ID 8):

    function child_before_loop () {
    
    	global $query_string;
    
    	query_posts($query_string . "&order=ASC&orderby=date&cat=8");

    This worked fine for the one category – however, all other categories returned the “Sorry, no posts matched your criteria” message. Any suggestions?

    if (you === ‘helpful’) { me===’very grateful’; }

    Thanks a million.

    • This topic was modified 11 months, 3 weeks ago by  scallemang.
    • This topic was modified 11 months, 3 weeks ago by  scallemang.
    http://www.read2rap.com
    #55468

    David Chu
    Participant
    Post count: 1317

    Hi,
    A witty presentation. :-)

    I’ll shoot from the hip – depending on where you are in the template and/or loop, something like this should work, I think, to make it operative only on Category 8. The idea is to contain your line in an IF statement. Check me, as I didn’t test this:

    [php]
    if ( is_category( ’8′ ) ) {
    query_posts($query_string . "&order=ASC&orderby=date&cat=8");
    }
    [/php]

    Cheers, Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #55523

    scallemang
    Participant
    Post count: 4

    Got it working with your code. You rule!

    In case any other PHP-neophytes stumble upon this, here is the full code I used in the functions.php file (replace the category number with your own):

    add_action('genesis_before_loop', 'child_before_loop');
    
    function child_before_loop () {
    
    	global $query_string;
    	if ( is_category( '123' ) )  {
        query_posts($query_string . "&order=ASC&orderby=date&cat=123");
    	}
    }
    #55528

    David Chu
    Participant
    Post count: 1317

    Great!
    And I salute you for being willing to try PHP. You’ll go a lot further with Genesis than those who won’t!

    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #99872

    JHSEsq
    Member
    Post count: 3

    Using the Wintersong theme, that code did NOT work for me.
    And worse, I’ve tried at least three different plugins specifically designed to allow post category pages to display the posts in ascending, rather than descending, date order. None of those plugins work either! (Including Different Posts per Page by Max Blog Press.)
    So . . . I can only conclude there must be something in the Genesis or child theme code that is overriding the plugins and/or the code suggested above.
    Can anyone help?

    Thanks!

    • This reply was modified 3 months, 2 weeks ago by  JHSEsq.
    • This reply was modified 3 months, 2 weeks ago by  JHSEsq.
    #111841

    jodzeee
    Participant
    Post count: 212

    It worked for me, thanks much!

    #111847

    braddalton
    Participant
    Post count: 8871

    Never Use Query Posts

    Use pre_get_posts http://wpsites.net/wordpress-tips/reverse-post-order-for-category-archive/


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #112016

    jodzeee
    Participant
    Post count: 212

    Thanks, Brad. Really appreciate your help!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.