get_category_parents [ WordPress Function ]
get_category_parents ( $id, $link = false, $separator = '/', $nicename = false, $visited = array() )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: get_category_by_path, get_category_children, get_categories, get_category_link, get_the_category_rss
Retrieve category parents with separator.
Source
<?php
function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
$chain = '';
$parent = &get_category( $id );
if ( is_wp_error( $parent ) )
return $parent;
if ( $nicename )
$name = $parent->slug;
else
$name = $parent->name;
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
$visited[] = $parent->parent;
$chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
}
if ( $link )
$chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
else
$chain .= $name.$separator;
return $chain;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get category parents « WordPress Codex
Description. Returns a list of the parents of a category, including the category, in hierarchical order. Usage. <?php echo get_category_parents($category, ...
codex.wordpress.org - WordPress › Support » get_category_parents with no end separator
Does anyone know how to display the parent category and then sub-category with a separator in between, but not at the end of the line? I'm using this: ...
wordpress.org - WordPress › Support » Tags — get_category_parents
(forgot?) Register · WordPress › Support » get_category_parents. Tag: get_category_parents Add New » ... get_category_parents question, 1, rodeftone, 1 year ...
wordpress.org - Exclude category from get_category_parents (wordpress) - Stack ...
$cat = get_the_category(); $cat = $cat[0]->term_id; // next will return an array of all category ancestors, with toplevel cat being [0] $ancestors ...
stackoverflow.com
Gebruikersdiscussies [ wordpress.org ]
- trixienolix on "Using categories as crumbtrail whilst excluding a category"
- trixienolix on "Using categories as crumbtrail whilst excluding a category"
- rodeftone on "get_category_parents question"
- Ipstenu on "Documentation of Function Reference/get category parents"
- Hello World on "Documentation of Function Reference/get category parents"
- FrancescoRizzi on "Skipping the leaf?"
- FrancescoRizzi on "Skipping the leaf?"
- Michael Fields on "reverse get_category_parents"
- smeknamn on "reverse get_category_parents"
- fooentes on "reverse get_category_parents"