Changing post order on category page and Mega menu

Posted in: Newspaper
Post count: 7

Hi guys,

I would like to sort the order of the posts on the category page and in the mega menu.
How can I do this?

Thanks!
Bianca

Post count: 6600

Hi,

Add this function into the functions.php file, like this: http://screencast.com/t/42g35dlHA
This will allow you to modify the sort order of post on category page:

function foo_modify_query_order( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'DESC' );
    }
}
add_action( 'pre_get_posts', 'foo_modify_query_order' );

Change the order as you like.

For the Mega menu you have to add this line of code $atts['sort'] = 'alphabetical_order';, like this:
http://screencast.com/t/0OmLDPNkD9U
Change the sort order as you like, using the values set for sort here: http://screencast.com/t/Gv2I6uUs

Thanks

Post count: 7

Thanks for the solution! It works perfectly. 🙂

Post count: 9

Lucian — that worked great for alphabetizing categories. Are you able to provide the code to alphabetize tag listings?

Post count: 7909

Hi,

Please try to add also this to the above code – http://screencast.com/t/caXaQ9E7Xgcu

function foo_modify_query_order( $query ) {
    if ( $query->is_category() || $query->is_tag() && $query->is_main_query() ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'DESC' );
    }
}
add_action( 'pre_get_posts', 'foo_modify_query_order' );

Thanks!

Post count: 9

And … BOOM! Worked perfectly. Thanks so much, Alin, for the quick and helpful reply!

Post count: 8

Hi Lucian,

That is exactly what I need – Unfortunately both screencast links (added in blockquote) are not able to be displayed anymore. Is it possible for you to update them?! That would be a great help. Thanks in advance!

Hi,

Add this function into the
functions.php
file, like this: http://screencast.com/t/42g35dlHA
This will allow you to modify the sort order of post on category page:

function foo_modify_query_order( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); $query->set( ‘order’, ‘DESC’ ); } } add_action( ‘pre_get_posts’, ‘foo_modify_query_order’ );

Change the order as you like.

For the Mega menu you have to add this line of code
$atts[‘sort’] = ‘alphabetical_order’;
, like this:
http://screencast.com/t/0OmLDPNkD9U
Change the sort order as you like, using the values set for sort here: http://screencast.com/t/Gv2I6uUs

Thanks

Post count: 8

The snippets mentioned above only work if “category global theme panel settings” are set to “normal pagination”.

Are you able to provide a snippet that also works with pagination set to ‘infinite loading’ or ‘infinite loading + load more’?!

Post count: 22421

Hello,

Sorry but it will not work with other types of pagination. You will need to use a category sort order plugin for that but I’m not sure it will work as we never tested such a plugin. It is worth a try though.

Thanks.

Post count: 101

Hi Lucian.

I am trying to sort posts in category “camera-eye” (nr. 306) in the mega menu according to a custom field called “concertdatum”. However I keep failing miserably.

For this to work I have added the sorting option concertdatum like so:
/includes/wp_booster/td_data_source.php

            case 'concertdatum':       
                $wp_query_args['meta_key'] = 'datum';
                $wp_query_args['meta_type'] = 'DATETIME';            
                $wp_query_args['orderby'] = 'meta_value';
                $wp_query_args['order'] = 'DESC';
            break;  

Then I have changed the following to the mega menu file:
/includes/shortcodes/td_block_mega_menu.php
class td_block_mega_menu extends td_block {

    function render($atts, $content = null){
              if (is_category( '306' )){ 
          $atts['sort'] = 'concertdatum'; 
          parent::render($atts);}
	    $buffy_categories = '';

	    extract(shortcode_atts(
		    array(
			    'limit' => 5,
			    'sort' => '',
			    'category_id' => '',
			    'category_ids' => '',
			    'custom_title' => '',
			    'custom_url' => '',
			    'show_child_cat' => '',  //the child category number
			    'sub_cat_ajax' => '' //empty we use ajax
		    ), $atts));

	    if (!empty($show_child_cat) and
	        !empty($category_id)) {

		    // check for subcats existence
		    $td_subcats = get_categories(array(
                'child_of' => $category_id,
                'number' => 1
            ));

		    if (!empty($td_subcats)) {
			    $atts['limit'] = 4; //alter the loop because we don't have space now with the categories
		    }
	    }

	    parent::render($atts); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)
                                             
	    //get subcategories, it returns false if there are no categories
	    $get_block_sub_cats = $this->get_mega_menu_subcategories($atts);

	     $additional_classes = array();

But sadly nothing happens, can you help me out what I’m doing wrong please ?

Post count: 23312

Hi NickDeBaerdemaeker,

Unfortunately, this is not a simple task and if you are not aware of the steps which are needed to take in this case, please consider hiring a freelancer/developer to help you because we cannot provide custom work at the moment, sorry! We cannot provide additional customization at the moment, sorry! You can try using such a plugin with this functionality from here -> https://wordpress.org/plugins/custom-taxonomy-order-ne/

The plugin Category Order and Taxonomy Terms Order might be useful to you because I saw that many users use it to change the categories order.

Hope this helps!

Thanks.

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