Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #598937

    Dear Kriesi,

    I am using portfolio post categories as ‘filters’ to display different items within a Masonry Grid element (see url link below)

    The categories are displayed in alphabetical order – L, M, S, XL
    But I want the order to be the logical sequence S, M, L, XL

    How can I override the alphabetical order for the category filters?

    Thanks and best wishes,
    Richard

    #600313

    Hi Richard!

    Thank you for using Enfold.

    This is possible but you have to modify the config-templatebuilder > aviashortcodes > helper-masonry.php file. Add this code on line 148:

    $order = array(3, 5, 2, 4);
    				usort($sort_terms, function ($a, $b) use ($order) {
    				    $ap = array_search($a->term_id, $order);
    				    $bp = array_search($b->term_id, $order);
    				    return $ap - $bp;
    				});

    .. or right above this code (line 149)

    //$output .= "</div>";
    				$output .= "</div></div>";
    

    Adjust the value of the $order array based on the id of the “size” categories.

    Regards,
    Ismael

    #600322

    Thanks Ismael, but I get syntax errors when I add that code.

    I’m copying here the section of code immediately before and after lines 148, from line 135 – 151.
    Could you insert the code you in the correct place within these sections, so I can copy and paste back into helper-masonry.php

    Thanks, Richard

    foreach($sort_terms as $term)
    {
    $show_item = in_array($term->term_id, $current_page_terms) ? ‘avia_show_sort’ : ‘avia_hide_sort’;
    if(!isset($term_count[$term->term_id])) $term_count[$term->term_id] = 0;
    $term->slug = str_replace(‘%’, ”, $term->slug);

    $output .= “<span class=’text-sep {$term->slug}_sort_sep {$show_item}’>/</span>”;
    $output .= ‘slug.’_sort” class=”‘.$term->slug.’_sort_button ‘.$show_item.'” ><span class=”inner_sort_button”>’;
    $output .= “<span>”.esc_html(trim($term->name)).”</span>”;
    $output .= “<small class=’avia-term-count’> “.$term_count[$term->term_id].” </small></span>”;
    $output .= “
    “;
    }

    //$output .= “</div>”;
    $output .= “</div></div>”;
    }

    #601256

    Hey!

    Thank you for coming back.

    I added a filter to the core. Until this filter is release, please add the following line to enfold\config-templatebuilder\avia-shortcodes\helper-masonry.php line 141ff:

    Old code:

    
    				$sort_loop = "";
    				$allowed_terms = array();
    				
    				foreach($sort_terms as $term)
    				{
    

    New code:

    
    				$sort_loop = "";
    				$allowed_terms = array();
    				
    				$sort_terms = apply_filters('avf_masonry_resort_filter_buttons', "", $sort_terms, $this->atts );
    				
    				foreach($sort_terms as $term)
    				{
    

    Add following code to Functions.php file of your child theme (or parent theme, if not using a child theme)- you can use Dashboard -> Appearance > Editor (this code does the actual resorting):

    
    
    add_filter( 'avf_masonry_resort_filter_buttons', 'my_avf_masonry_resort_filter_buttons', 10, 2 );
    function my_avf_masonry_resort_filter_buttons( $sort_terms, $atts )
    {
    		//	Add Sequence of term names you like
    	$order = array( 'S', 'M', 'L', 'XL' );
    	
    	$new_sort = array();
    	
    	foreach( $order as $value )
    	{
    		foreach( $sort_terms as $key => $term )
    		{
    			if( strtoupper( trim( $term->name ) ) == strtoupper( trim( $value ) ))
    			{
    				$new_sort[] = $term;
    				unset( $sort_terms[ $key ] );
    			}
    		}
    	}
    	
    	$new_sort = array_merge( $new_sort, $sort_terms );
    	
    	return $new_sort;
    }
    

    Regards,
    Günter

    #601855

    Thank you Günter,

    So in the next Enfold release there will be an option to re-order the category filters from within the Portfolio Grid? That sounds excellent. When will the next version be released do you think?

    Another question – in the portfolio categories you allow categories to be nested in a parent category, but all categories assigned to a post appear in one block when category filters are turned on for a portfolio grid.

    Is there some way that the categories nested within one parent could be displayed together, say on one line, and categories nested within another parent could be displayed separately on another line.

    This is because I want to filter projects by two different criteria – location and size, something like this:

    Europe / North America / Asia / Africa
    Small / Medium / Large / Extra Large

    Thanks, Richard

    #602120

    Hi Günter,

    There was a new version of Enfold released today but I don’t see anything that changes the way the masonry grid category filters are displayed. Perhaps this will be in the next version?

    I’m having some problems implementing the code you suggested. In helper-masonry.php there is no code that matches the code you say I should replace?

    Also, I’ve also not been able to find IDs displayed anywhere in the admin to specify a custom order for the category filters as you said.

    Thanks, Richard

    #603041

    Hey!

    Thank you for coming back.

    Sorry for the late reply, but we have a lot to do in the moment.

    Currently it is not intended to add this as an option to the admin.
    You can post a feature request on https://kriesi.at/support/enfold-feature-requests/. Kriesi looks at these reguarly and decides, what to implement or develop.

    Back to your problem:

    I can help you to add the filter and the code to functions.php – I need ftp access and a temporary admin account. You can post it here safely in private content.

    Concerning Subcategories – currently not possible but you can post a feature request.

    Cheers!
    Günter

    #603068

    Thank you Günter,

    Will this mean that if we add the code to functions.php in the WordPress admin, that I can updated future versions of Enfold without affecting this change?

    The custom order for the ‘Size’ categories should be All, S, M, L, XL

    I’m posting a login below

    Thanks, Richard

    #603194

    Hey!

    The login does not work – can you check pls.

    Tu update helper-masonry.php I need an ftp access – cannot reach that file from the admin panel.

    If you are using a child theme – you only have to add the “add_filter” section once, unless you update the child theme.

    If you use a parent theme, you have to add it after every update.

    The changes to helper-masonry.php have to be done after every update ( until Kriesi adds it to the core – which he did not do until now ).

    Cheers!
    Günter

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.