onetone_breadcrumbs_get_term_parents

The Onetone onetone breadcrumbs get term parents function.

Description

onetone_breadcrumbs_get_term_parents( (string) $parent_id = '', (string) $taxonomy = '' ); 

Parameters (2)

0. $parent_id — Optional. (string) => ''
The parent id.
1. $taxonomy — Optional. (string) => ''
The taxonomy.

Usage

  1. if ( !function_exists( 'onetone_breadcrumbs_get_term_parents' ) ) { 
  2. require_once '/includes/class-breadcrumb.php'; 
  3.  
  4. // The parent id. 
  5. $parent_id = ''; 
  6.  
  7. // The taxonomy. 
  8. $taxonomy = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = onetone_breadcrumbs_get_term_parents($parent_id, $taxonomy); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/class-breadcrumb.php  
  1. function onetone_breadcrumbs_get_term_parents( $parent_id = '', $taxonomy = '' ) { 
  2.  
  3. /** Set up some default arrays. */ 
  4. $trail = array(); 
  5. $parents = array(); 
  6.  
  7. /** If no term parent ID or taxonomy is given, return an empty array. */ 
  8. if ( empty( $parent_id ) || empty( $taxonomy ) ) 
  9. return $trail; 
  10.  
  11. /** While there is a parent ID, add the parent term link to the $parents array. */ 
  12. while ( $parent_id ) { 
  13.  
  14. /** Get the parent term. */ 
  15. $parent = get_term( $parent_id, $taxonomy ); 
  16.  
  17. /** Add the formatted term link to the array of parent terms. */ 
  18. $parents[] = '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( $parent->name ) . '">' . $parent->name . '</a>'; 
  19.  
  20. /** Set the parent term's parent as the parent ID. */ 
  21. $parent_id = $parent->parent; 
  22.  
  23. /** If we have parent terms, reverse the array to put them in the proper order for the trail. */ 
  24. if ( !empty( $parents ) ) 
  25. $trail = array_reverse( $parents ); 
  26.  
  27. /** Return the trail of parent terms. */ 
  28. return $trail; 
  29.  
  30. } // End onetone_breadcrumbs_get_term_parents()