• I have a category on my site and under that category are all the posts that I have put in there. This is a series of posts about a trip, day by day.

    Problem is, they are meant to be read by date, so that if a person clicks that category I would like them to see day 1 first, whereas now they see day 10 and have to scroll down to the botton to get to day one.

    Is there some sort of simple fix for this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You should be able to add this line above your loop on the category template:

    query_posts( array ( 'category_name' => 'my-category-slug', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC' ) );

    You will have to write some code to pass in the actual category slug you need depending on the category the user chooses.

    Thread Starter candyg333

    (@candyg333)

    Thanks…..that lets me out I am afraid. I don’t write code at all….scares me to death. For now, I will just live with it.

    I realize that putting code into a template can be daunting. I have searched through the plugins and most want to do re-order by drag and drop. Here is a function that you can copy and paste directly into your functions.php in your theme (or your child theme) and it should sort all posts by date in ascending order. I know you don’t like to code but perhaps just copy and pasting a block of code into a specific file might be easier. I do apologize but I code most of my solutions myself and try to stay away from plugins for simple things.

    // Runs before the posts are fetched
    add_filter( 'pre_get_posts' , 'my_change_order' );
    // Function accepting current query
    function my_change_order( $query ) {
    	// Check if the query is for an archive
    	if($query->is_archive)
    		// Query was for archive, then set order
    		$query->set( 'order' , 'asc' );
    	// Return the query (else there's no more query, oops!)
    	return $query;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Chronoligically lists posts under each category’ is closed to new replies.