get_the_category_list [ WordPress Function ]
get_the_category_list ( $separator = '', $parents = '', $post_id = false )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: get_the_category_rss, get_the_category, get_the_term_list, get_the_category_by_id, get_the_tag_list
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_taxonomy( get_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->parent, true, $separator );
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
break;
case 'single':
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, false, $separator );
$thelist .= $category->name.'</a></li>';
break;
case '':
default:
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
}
}
$thelist .= '</ul>';
} else {
$i = 0;
foreach ( $categories as $category ) {
if ( 0 < $i )
$thelist .= $separator;
switch ( strtolower( $parents ) ) {
case 'multiple':
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, true, $separator );
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
break;
case 'single':
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, false, $separator );
$thelist .= "$category->name</a>";
break;
case '':
default:
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
}
++$i;
}
}
return apply_filters( 'the_category', $thelist, $separator, $parents );
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get the category list « WordPress Codex
Description. Retrieve category list in either HTML list or custom format. Generally used for quick, delimited (eg: comma-separated) lists of categories, as part of a ...
codex.wordpress.org - How to exclude categories from get_the_category_list? - WordPress
There is indeed an under-documented get_the_category_list function. I wanted to exclude "Artwork" and "Gallery" from my listings in the manner you described ...
wordpress.org - WordPress › Support » get_the_category_list
Hi, I'm building a wordpress site using the Autofocus template and I'm having problems with the meta part. The thing is that one the single.php pages I want to ...
wordpress.org - categories - Display only one result from "get_the_category_list ...
Mar 21, 2011 ... I'd like get_the_category_list to only display one or two categories instead of all the categories associated with the post. Haven't been able to ...
wordpress.stackexchange.com
Gebruikersdiscussies [ wordpress.org ]
- rebekahford on "How to exclude categories from get_the_category_list?"
- ddmarker on "How to exclude categories from get_the_category_list?"
- rebekahford on "How to exclude categories from get_the_category_list?"
- akamediasystem on "How to exclude categories from get_the_category_list?"
- rebekahford on "How to exclude categories from get_the_category_list?"
- akamediasystem on "How to exclude categories from get_the_category_list?"
- rebekahford on "How to exclude categories from get_the_category_list?"
- rebekahford on "How to exclude categories from get_the_category_list?"
- akamediasystem on "How to exclude categories from get_the_category_list?"
- esmi on "How to exclude categories from get_the_category_list?"