• Hi.

    We are using a mega menu navigation bar on our site.
    In short, this displayes the subcategories and shows the 4 most recent posts in said category.

    However, for one of these we really want to change “the most recent published”, to the “most recent event date”.

    According to the theme support this *can* be done, but they aren’t really willing to spend the time on it.

    I reckon this should be possible via an if is in category statement, however I’m stuck. Could anyone help me here ?

    This is the piece of code that needs adjusting.

    class td_block_mega_menu extends td_block {
      
        function render($atts, $content = null){
          
    	    $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();
    
            //we have subcategories
            if ($get_block_sub_cats !== false) {
                $buffy_categories .= '<div class="td_mega_menu_sub_cats">';
                //get the sub category filter for this block
                $buffy_categories .= $get_block_sub_cats;
                $buffy_categories .= '</div>';
            } else {
                $additional_classes []= 'td-no-subcats';
            }
    
            $buffy = ''; //output buffer
    
            //custom categories
       
            //end custom categories

    Now what I have tried to implement is this, with no change:

             if (is_category( 306 )) {
            $atts['sort'] = 'concertdatum';
                parent::render($atts);
        }   

    The $atts [sort] attribute and the subsequent parent::render is what makes the change in sorting. This happens when I leave out the if is category bit.

    Any help much appreciated, Nick.
    https://www.screencast.com/t/jgjknQvhwDwh

    • This topic was modified 5 years, 11 months ago by nessler.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The solution depends on what are accepted arguments by the query being run. Guessing wildly that it is somehow related to WP_Query class and your event dates are in meta data, you’d set the arguments more like this:

    $atts['meta_key'] = 'concertdatum';
    $atts['sort'] = 'meta_value';

    Your dates need to be either timestamps or formatted as “yyyy-mm-dd” for the ordering to be correct.

Viewing 1 replies (of 1 total)
  • The topic ‘Sorting one category differently in a mega menu’ is closed to new replies.