Switch language

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




get_the_taxonomies [ WordPress Function ]

get_the_taxonomies ( $post = 0, $args = array() )
Parameters:
  • (int) $post Optional. Post ID or will use Global Post ID (in loop).
  • (array) $args Override the defaults.
Returns:
  • (array)
Defined at:



Retrieve all taxonomies associated with a post.

This function can be used within the loop. It will also return an array of the taxonomies with links to the taxonomy and name.

Source


<?php
function get_the_taxonomies($post 0$args = array() ) {
    if ( 
is_int($post) )
        
$post =& get_post($post);
    elseif ( !
is_object($post) )
        
$post =& $GLOBALS['post'];

    
$args wp_parse_args$args, array(
        
'template' => '%s: %l.',
    ) );
    
extract$argsEXTR_SKIP );

    
$taxonomies = array();

    if ( !
$post )
        return 
$taxonomies;

    foreach ( 
get_object_taxonomies($post) as $taxonomy ) {
        
$t = (array) get_taxonomy($taxonomy);
        if ( empty(
$t['label']) )
            
$t['label'] = $taxonomy;
        if ( empty(
$t['args']) )
            
$t['args'] = array();
        if ( empty(
$t['template']) )
            
$t['template'] = $template;

        
$terms get_object_term_cache($post->ID$taxonomy);
        if ( empty(
$terms) )
            
$terms wp_get_object_terms($post->ID$taxonomy$t['args']);

        
$links = array();

        foreach ( 
$terms as $term )
            
$links[] = "<a href='" esc_attrget_term_link($term) ) . "'>$term->name</a>";

        if ( 
$links )
            
$taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links$terms);
    }
    return 
$taxonomies;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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