WordPress.org

Forums

Custom post types hierarchical custom taxonomies and breadcrumbs (5 posts)

  1. ashgoodman
    Member
    Posted 4 years ago #

    Hi

    I have a project coming up that will make heavy use to custom post types and hierarchical custom taxonomies. The client wants breadcrumb navigation and I was just wondering the state of support for this with you plugin.

    Does it presently support it? If not is there a beta version that does? I would be happy to help with testing!

    Thanks!

    Ash

  2. Alex Cragg
    Member
    Posted 4 years ago #

    I'm interested in this too.

  3. nicomollet
    Member
    Posted 4 years ago #

    I wanted this feature too and I added support for hierarchical custom taxonomies, so that I can have both :

    Home > Taxonomy > Sub-Taxonomy
    or
    Home > Taxonomy > Sub-Taxonomy > Custom Post Type Title

    For the 2nd example, the taxonomy in the breadcrumb is the 1st taxonomy of your custom post type.
    If you have custom post type "movie", and have 2 taxonomies : non-hierarchical "actors", and hierarchical "movie_genre", then "movie_genre" must the the 1st taxonomy registered in your custom post type "movie".

    in yoast-breadcrumbs.php :

    Line 168 :

    // replace
    global $wp_query, $post;
    // by
    global $wp_query, $post,$wp_post_types;

    Line 228, paste :

    // BEGIN support taxonomies hierarchy
    $post_types = $wp_post_types;
    unset($post_types['post'],$post_types['page'],$post_types['nav_menu_item'],$post_types['revision'],$post_types['attachment']);
    if((($pn = get_query_var('pagename')) || (($pn = get_query_var('post_type')) && !get_query_var('p') && !get_query_var($pn))) && isset($post_types[$pn])){
        echo $post_type_name  = $post_types[$pn]->labels->name;
    }elseif(($post_type = get_query_var('post_type')) && get_query_var($post_type)){
        $custom_post_tax = $post_types[$post_type]->taxonomies[0];
        $terms = wp_get_post_terms($GLOBALS['wp_query']->get_queried_object_id(), $custom_post_tax);
    
        $term_parents[] = array('name'=>$terms[0]->name, 'url'=>get_term_link($terms[0], $custom_post_tax));
        $term_parent = $terms[0]->parent;
        while($term_parent){
            $term = get_term($term_parent, $custom_post_tax);
            $term_parent = $term->parent;
            $term_parents[] = array('name'=>$term->name, 'url'=>get_term_link((int)$term->term_id, $custom_post_tax));
        }
        if(!empty($term_parents)){
            $term_parents = array_reverse($term_parents);
            foreach($term_parents as $term){
                $output .= '<a href="'.$term['url'].'">'.$term['name'].'</a> ' . $opt['sep'].' ';
            };
        }
    }
    if(is_tax()){
        $term = get_term($GLOBALS['wp_query']->get_queried_object_id(), get_query_var('taxonomy'));
        $term_name = $term->name;
        $term_parent = $term->parent;
        while($term_parent){
            $term = get_term($term_parent, get_query_var('taxonomy'));
            $term_parent = $term->parent;
            $term_parents[] = array('name'=>$term->name, 'url'=>get_term_link((int)$term->term_id, get_query_var('taxonomy')));
        }
        if(!empty($term_parents)){
            $term_parents = array_reverse($term_parents);
            foreach($term_parents as $term){
                $output .=  '<a href="'.$term['url'].'">'.$term['name'].'</a> ' . $opt['sep'].' ';
            };
        }
    }
    // END support taxonomies hierarchy
  4. m2ew
    Member
    Posted 4 years ago #

    I've had issues with single.php and listing a hierarchal taxonomy in order.
    wp_list_categories works well for this, but there is an issue with changing the separator (i.e. [br/]) when you set the list style to 'none'.

    http://wordpress.stackexchange.com/questions/646/wordpress-remove-br-separator-from-last-item-in-wp-list-categories is a great example of how to set this up using the php's implode / explode. However, this can be more automated by adding it to a function in themes functions.php file. All I changed was the $output var formatting.

    Here is the function I have:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    to call this in your single.php setup you $args the same as if you were using wp_list_categories.

    wwp_posttype_breadcrumb( $args );

    If you want to change the seperator just add
    $myseperator = ":";
    wwp_posttype_breadcrumb( $args , $myseperator);

    Here is the reference link for wp_list_categories
    http://codex.wordpress.org/Function_Reference/wp_list_categories

  5. m2ew
    Member
    Posted 4 years ago #

    here is the link to the function
    http://wordpress.pastebin.com/pjgQCbjQ

Topic Closed

This topic has been closed to new replies.

About this Topic