• Hi, this is a breadcrumb.

    I have a question. Currently, the plugin only shows the first category of you have multiple categories on a post.

    Which filter do you recommend that I use so I can show all category that’s part of a post?

    Also, is there a way to rearrange the position of a post categories on the trail? For example, if a post shows categories to be first, second, can I change the trail to show second, first?

    Thank you.

    • This topic was modified 1 year, 9 months ago by Manny.
Viewing 1 replies (of 1 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi Manny @mannyo, thank you for your feedback.

    Although I don’t recommend showing all categories on the breadcrumb, you can get it done by using the filter ‘breadcrumb_block_get_items’. Here is the sample code:

    add_filter( 'breadcrumb_block_get_items', function($items, $breadcrumb_instance) {
    	if ( is_singular('post') || is_singular('page') ) {
    		// Global post.
    		global $post;
    		
    		// Overide the all breadcrumb items.
    		// Reset.
    		$breadcrumb_instance->reset();
    		
    		// Home link.
    		$breadcrumb_instance->add_crumbs_front_page();
    
    		// Get all categories.
    		$categories = get_the_category( $post );
    		if ( ! empty( $categories ) ) {
    			foreach( $categories as $category ) {
    				$breadcrumb_instance->add_item( $category->name, get_category_link( $category->term_id ) );
    			}
    		}
    
    		// Current post/page.
    		$breadcrumb_instance->add_item( get_the_title( $post ), get_permalink( $post ), [ 'aria-current' => 'page' ] );
    
    		$items = $breadcrumb_instance->get_items();
    	}
    
    	return $items;
    }, 10, 2);

    I’ve not had time to test the above code, but that’s the idea to solve it.

    There is no functionality for sorting categories on this block, but there will be a functionality for you to choose a category/taxonomy as the primary category/taxonomy to show on the breadcrumb in the future version

    Thanks, Phi.

    • This reply was modified 1 year, 9 months ago by Phi Phan.
Viewing 1 replies (of 1 total)
  • The topic ‘Showing all post category on the breadcrumb’ is closed to new replies.