Community Forums › Forums › Archived Forums › Design Tips and Tricks › Reverse Post Order for Single Category
Tagged: categories
- This topic has 8 replies, 6 voices, and was last updated 10 years, 8 months ago by
adougherty.
-
AuthorPosts
-
August 10, 2013 at 9:16 am #55465
scallemang
MemberHi 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.comAugust 10, 2013 at 9:38 am #55468David Chu
ParticipantHi,
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 #55523scallemang
MemberGot 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 #55528David Chu
ParticipantGreat!
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 #99872JHSEsq
MemberUsing 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 #111841jodzeee
MemberIt worked for me, thanks much!
June 28, 2014 at 12:36 am #111847Brad Dalton
ParticipantNever Use Query Posts
Use pre_get_posts http://wpsites.net/wordpress-tips/reverse-post-order-for-category-archive/
June 29, 2014 at 2:25 pm #112016jodzeee
MemberThanks, Brad. Really appreciate your help!
October 8, 2015 at 2:00 pm #167690adougherty
ParticipantWorked like I charm for me. Thank you for posting the complete, working code block!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.