• I have, what I hope will be be, an easy question. Some of my posts are part of a series. When readers click on that particular category, I wold like the resulting page to list the posts starting with the first in the series (oldest post).

    I’ve found plugins that allow me to manually sort but I need it done automatically. I also have seen plugins that I think might work but they require adding to the .php file and I know nothing about that.

    Does anyone have any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • consider to use ‘pre_get_posts’

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    example, to be added to functions.php of the theme:

    function category_posts_sort( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( is_category( array( 'aciform', 'uncategorized' ) ) ) { //replace with your particular categories//
            $query->set( 'order', 'ASC' );
            return;
        }
    
    }
    add_action( 'pre_get_posts', 'category_posts_sort', 1 );

    I also found this similar code (I think at http://wordpress.stackexchange.com/questions ?):

    function wpsf_orderby( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
     // do conditional checks here and return on false.?
    
        if ( is_category('uncategorized') ) {
    	remove_action( 'pre_get_posts', __FUNCTION__ );
    	add_filter( 'posts_orderby', function() { return ' post_title ASC'; } );
    	}
    }
    
    add_action( 'pre_get_posts', 'wpsf_orderby' );

    http://codex.wordpress.org/Function_Reference/is_category

    Thread Starter JerryWhite

    (@jerrywhite)

    alchymyth, thanks for the prompt response but I have absolutely no idea what to do with the code above. That’s why I’m looking for a plug-in.

    I looked at the links you list and when you talk about “hooks” and “loops” it sounds like words my grandma used with knitting.

    [bump moderated]

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sorting Category Post page’ is closed to new replies.