Category refuses to reverse order

Posted in: Newspaper
Post count: 88

Hi there.

A portion of my website contains of a static tutorial series. Therefore it makes most sense to display the oldest post first (descending). Faking the publishing date is not an option because that will mess up the “next page” buttons (that I just got working in my previous topic :P).

I have tried to create an override in functions.php but it is not having any effect:

add_action('wp_head', 'custom_change_posts_order');
function custom_change_posts_order() {
    global $query_string;
    if (in_category(array(10,11,12,13,14,15,34,35,36))) {
        $posts = query_posts( $query_string . '&orderby=date&order=desc' );
    }
}

Any thoughts on why the function is not affecting the category pages?

Post count: 6535

Hi

For the condition you’re using in_category function which check if a post belongs or not to a specified category. To check if a category page it’s displayed you have to use is_category. Try the code below in functions.php it should work fine:

add_action('wp_head', 'custom_change_posts_order');
function custom_change_posts_order() {
	global $query_string;
	if (is_category(array(10,11,12,13,14,15,34,35,36))) {
		$posts = query_posts( $query_string . '&orderby=date&order=asc' );
	}
}

Thanks!

  • This reply was modified 10 years by Andrei L..
Post count: 88

Amazing! This was pretty much the last thing that stopped me from changing over from Joomla to WordPress :). Now I “only” have to find new featured images for 126 posts :P.

Thanks and have a nice day.

Post count: 6535

Hi

Glad I could help.
Have a nice day.

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.