• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Reverse Post Order for Single Category

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: not resolved

Tagged: categories

  • This topic has 8 replies, 6 voices, and was last updated 7 years, 12 months ago by adougherty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • August 10, 2013 at 9:16 am #55465
    scallemang
    Member

    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.

    http://www.read2rap.com
    August 10, 2013 at 9:38 am #55468
    David Chu
    Participant

    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:

    if ( is_category( '8' ) )  {
        query_posts($query_string . "&order=ASC&orderby=date&cat=8");
    }
    

    Cheers, Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    August 10, 2013 at 2:33 pm #55523
    scallemang
    Member

    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");
    	}
    }
    August 10, 2013 at 2:48 pm #55528
    David Chu
    Participant

    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

    April 12, 2014 at 7:53 pm #99872
    JHSEsq
    Member

    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!

    June 27, 2014 at 11:11 pm #111841
    jodzeee
    Member

    It worked for me, thanks much!

    June 28, 2014 at 12:36 am #111847
    Brad Dalton
    Participant

    Never Use Query Posts

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


    Tutorials for StudioPress Themes & WooCommerce.

    June 29, 2014 at 2:25 pm #112016
    jodzeee
    Member

    Thanks, Brad. Really appreciate your help!

    October 8, 2015 at 2:00 pm #167690
    adougherty
    Participant

    Worked like I charm for me. Thank you for posting the complete, working code block!

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble