Theme Support Forum

Support Forum for Free and Premium Themes. Premium Theme Forums are Private! Please log in first to see the Premium forums

If you Like the Asteria Lite Theme and want to Keep it free forever Please Rate it on Wordpress.org (It only takes a few seconds)
Viewing 2 posts - 1 through 2 (of 2 total)

Category Ascending Order?

Home Forums Free Theme Support Asteria Lite Category Ascending Order?

  • #438287

    Ryxe

    Hello, I’m trying to get the categories to display in ascending order (oldest to newest) rather than descending (newest to oldest). Does anyone know how to get this to work?

    Every time I add in a code to layout1.php (which is what the category.php is using) to sort it to ascending, such as <?php query_posts($query_string . ‘&orderby=date&order=ASC’); ?> it does sort it in the correct order, but then it displays posts from the other categories as well, which I don’t want. Is there a way to only sort ascending for that category’s posts and not have posts from other categories show?

    #440134

    Towfiq I.

    administrator

    Open up functions.php and replace this:

    function asteria_home_query($query) {
        if ( $query->is_home()) {
    		global $asteria;
    		set_query_var( 'post_type', 'post' );
    		set_query_var( 'paged', ( get_query_var('paged') ? get_query_var('paged') : 1) );
    		if(!empty($asteria['enable_cat'])){
    		$postcount = $asteria['n_posts_field_id'];
    		$postcat = $asteria['posts_cat_id'];
    		set_query_var( 'posts_per_page', ''.$postcount.'' );
    		if(!empty($asteria['posts_cat_id'])){set_query_var( 'cat', ''.implode(',', $postcat).'' );}
    		}
        }
    	
    }
    add_action( 'pre_get_posts', 'asteria_home_query' );

    with this:

    function asteria_home_query($query) {
        if ( $query->is_home()) {
    		global $asteria;
    		set_query_var( 'post_type', 'post' );
    		set_query_var( 'paged', ( get_query_var('paged') ? get_query_var('paged') : 1) );
    		if(!empty($asteria['enable_cat'])){
    		$postcount = $asteria['n_posts_field_id'];
    		$postcat = $asteria['posts_cat_id'];
    		set_query_var( 'posts_per_page', ''.$postcount.'' );
    		if(!empty($asteria['posts_cat_id'])){set_query_var( 'cat', ''.implode(',', $postcat).'' );}
    		}
        }
    	if ( $query->is_category()) {
    		set_query_var( 'order', 'ASC' );
    		}
    	
    }
    add_action( 'pre_get_posts', 'asteria_home_query' );

You must be logged in to reply to this topic.