This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tagged: 

How to choose category used in breadcrumb trail on single posts

  • Creator
    Topic
  • #7709
    jklassen
    Member

    Hello,

    I have enabled breadcrumbs display in Alyeska throughout my site. Most of the posts in my site are associated with 3 or more Categories. I don’t know how categories are selected for display in the Breadcrumbs trail. Is it by Category ID (lowest?), or some other logic.

    It would be very helpful if there was some way in which I could specify the primary category for a post, which would get used by the Alyeska theme’s breadcrumbs display. Right now, I end up with something unpredictable.

    I noticed a new WP plugin which seems to be seeking to address this issue of defining a primary category (http://wordpress.org/extend/plugins/wp-category-permalink/). But, after trying this, and seeing no difference in Alyeska, I just assume that this plugin adds some metadata to posts which Alyeska is obviously not aware of.

    Would anyone else know a method by which the breadcrumbs path category can be “controlled” or selected?

    Jeff

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #7720
    Jason Bobich
    Keymaster

    Hello Jeff,

    Yeah, there’s not really any great logic here.

    When a post is displayed, it needs a single category to build the trail from, like:

    Parent Category > Child Category > Post Title

    If there are multiple categories, this trail construction just wouldn’t work.

    The theme framework’s breadcrumb function essentially just calls WordPress’s get_the_category() function and then just takes the first category on the list to be used as that single category. WordPress returns this alphabetically, I believe. So the category chosen shouldn’t be random; it should be the highest ordered alphabetically. — So, category “Alpha” would get used over category “Beta”.

    That’s a cool idea, though, using that plugin. It looks like it essentially just saves the ID of the category to some mete data under “_category_permalink” for the given post. Also, WordPress’s get_the_category() has a filter that you could potentially manipulate the order returned.

    Here’s an example of what you could do from your own plugin or Child theme’s functions.php. This would essentially look for your “main” category from using that plugin and then just put it as the first category always when when WordPress returns the categories. Then the theme’s breadcrumb will use this because it’s first.

    function my_get_the_categories( $categories ){
    	
    	global $post;
    	$main_category = array();
    	$main_category_id = get_post_meta($post->ID, '_category_permalink', true);
    	
    	if( ! empty( $categories ) ) {
    		foreach( $categories as $key => $category ) {
    			if( $category->term_id == $main_category_id ) {
    				$main_category[] = $category;
    				unset($categories[$key]);
    			}
    		}
    	}
    
    	return array_merge($main_category, $categories);
    
    }
    add_filter('get_the_categories', 'my_get_the_categories');
    #7735
    jklassen
    Member

    Jason,

    Thank you for such a detailed reply. That is very much appreciated. I will see if I can implement you suggestion here.

    Jeff

Viewing 2 replies - 1 through 2 (of 2 total)
  • The forum ‘Alyeska Responsive WordPress Theme’ is closed to new topics and replies.