Ondersteuning » Code oplossingen gezocht » Facet navigatie tips?

  • Hallo! Net de Nederlandse page gevonden, ik hoop dat ik niet geflamed word omdat ik m’n engelse post hier copy/paste 😉


    I am working on a facet navigation for a big photo library listing. I got the filtered narrowing of photo results working here, through following code:

    $query = new WP_Query();
    
                            $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $args = array(
                            	'showposts' => 100,
                            	'orderby' => 'title',
                            	'order' => 'ASC',
                            	'post_type' => 'stockphotos',
                            	'paged' => $page,
                            	'tax_query' => array(
                            		'relation' => 'AND'
    							)
    						);
    
                            if ( !empty( $_GET['photofilter'] )) {
    
    	                        $applyFilters = explode(',', $_GET['photofilter'] );
    
    	                        foreach ( $applyFilters as $value ) {
    	                        	array_push( $args['tax_query'],
    									array(
    										'taxonomy' => 'photo-type',
    										'field' => 'slug',
    										'terms' => array( $value )
    	                        			)
    	                        		);
    	                        }
                            }

    For every keyword that is present, a tax_query is added and so eventually the listing will only show photos that contain ALL keywords selected by the user. Works well.

    Now what i’m missing, and pretty must the key feature of the facet navigation is the ‘relative to selection’ listing of categories, that changes it’s amount numbers based on the filters the user has selected.

    Stockphoto_Walker is custom, extending Category_Walker to add/remove parameters, general syntax is:

    wp_list_categories(
    	                      	array(
    
    	                      		'walker' => new Stockphoto_Walker(),
                          			'title_li' => '',
    	                      		'hierarchical ' => '1 ',
    	                      		'hide_empty' =>'0',
    	                      		'show_count' => '1',
    	                      		'taxonomy' => 'photo-type'
    								)
                          		);

    For example, no filters applied; the category walker shows:

    Green ( 10 )
    Yellow ( 4 )
    Garden ( 1 )
    Forest ( 9 )
    Beach ( 3 )
    Banana Tree ( 1 )

    Now when i hit Banana Tree as a filter, the photo listing will show the banana tree photo like you’d expect only the numbers from the category walker dont change. What i’d expect to be shown is:

    Green ( 1 )
    Yellow ( 1 )
    Garden ( 1 )
    Forest ( 1 )
    Beach ( 0 )
    Banana Tree ( 1 )

    Is more something like that, since the banana tree is listed under all categories with a 1.

    Okay, its obviously quite logical that this doesnt change by itself. For the wp_list_categories function doesn’t have fancy tax_query syntax like normal WP_Query does.

    Does anybody have an idea on how to achieve the result of my dreams here? To be used in PHP code and not a plugin.

    Curious, thanks for reading.

  • Het onderwerp ‘Facet navigatie tips?’ is gesloten voor nieuwe reacties.