Switch language

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




get_the_category_list [ WordPress Function ]

get_the_category_list ( $separator = '', $parents = '', $post_id = false )
Parameters:
  • (string) $separator Optional, default is empty string. Separator for between the categories.
  • (string) $parents Optional. How to display the parents.
  • (int) $post_id Optional. Post ID to retrieve categories.
Returns:
  • (string)
Defined at:



Retrieve category list in either HTML list or custom format.

Source


<?php
function get_the_category_list$separator ''$parents=''$post_id false ) {
    global 
$wp_rewrite;
    if ( ! 
is_object_in_taxonomyget_post_type$post_id ), 'category' ) )
        return 
apply_filters'the_category'''$separator$parents );

    
$categories get_the_category$post_id );
    if ( empty( 
$categories ) )
        return 
apply_filters'the_category'__'Uncategorized' ), $separator$parents );

    
$rel = ( is_object$wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' 'rel="category"';

    
$thelist '';
    if ( 
'' == $separator ) {
        
$thelist .= '<ul class="post-categories">';
        foreach ( 
$categories as $category ) {
            
$thelist .= "\n\t<li>";
            switch ( 
strtolower$parents ) ) {
                case 
'multiple':
                    if ( 
$category->parent )
                        
$thelist .= get_category_parents$category->parenttrue$separator );
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>' $category->name.'</a></li>';
                    break;
                case 
'single':
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>';
                    if ( 
$category->parent )
                        
$thelist .= get_category_parents$category->parentfalse$separator );
                    
$thelist .= $category->name.'</a></li>';
                    break;
                case 
'':
                default:
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>' $category->name.'</a></li>';
            }
        }
        
$thelist .= '</ul>';
    } else {
        
$i 0;
        foreach ( 
$categories as $category ) {
            if ( 
$i )
                
$thelist .= $separator;
            switch ( 
strtolower$parents ) ) {
                case 
'multiple':
                    if ( 
$category->parent )
                        
$thelist .= get_category_parents$category->parenttrue$separator );
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>' $category->name.'</a>';
                    break;
                case 
'single':
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>';
                    if ( 
$category->parent )
                        
$thelist .= get_category_parents$category->parentfalse$separator );
                    
$thelist .= "$category->name</a>";
                    break;
                case 
'':
                default:
                    
$thelist .= '<a href="' esc_urlget_category_link$category->term_id ) ) . '" title="' esc_attrsprintf__"View all posts in %s" ), $category->name ) ) . '" ' $rel '>' $category->name.'</a>';
            }
            ++
$i;
        }
    }
    return 
apply_filters'the_category'$thelist$separator$parents );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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