Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_category_parents [ WordPress Function ]

get_category_parents ( $id, $link = false, $separator = '/', $nicename = false, $visited = array() )
Parameters:
  • (int) $id Category ID.
  • (bool) $link Optional, default is false. Whether to format with link.
  • (string) $separator Optional, default is '/'. How to separate categories.
  • (bool) $nicename Optional, default is false. Whether to use nice name for display.
  • (array) $visited Optional. Already linked to categories to prevent duplicates.
Returns:
  • (string)
Defined at:



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_urlget_category_link$parent->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' $separator;
    else
        
$chain .= $name.$separator;
    return 
$chain;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics