get_the_category example



    /** * Filters the categories before building the category list. * * @since 4.4.0 * * @param WP_Term[] $categories An array of the post's categories. * @param int|false $post_id ID of the post to retrieve categories for. * When `false`, defaults to the current post in the loop. */
    $categories = apply_filters( 'the_category_list', get_the_category( $post_id )$post_id );

    if ( empty( $categories ) ) {
        /** This filter is documented in wp-includes/category-template.php */
        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">';
        

function the_category_ID($display = true) {
    _deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' );

    // Grab the first cat in the list.     $categories = get_the_category();
    $cat = $categories[0]->term_id;

    if ( $display )
        echo $cat;

    return $cat;
}

/** * Prints a category with optional text before and after. * * @since 0.71 * @deprecated 0.71 Use get_the_category_by_ID() * @see get_the_category_by_ID() * * @param string $before Optional. Text to display before the category. Default empty. * @param string $after Optional. Text to display after the category. Default empty. */

    $permalink = apply_filters( 'pre_post_link', $permalink$post$leavename );

    if (
        $permalink &&
        ! wp_force_plain_post_permalink( $post )
    ) {

        $category = '';
        if ( str_contains( $permalink, '%category%' ) ) {
            $cats = get_the_category( $post->ID );
            if ( $cats ) {
                $cats = wp_list_sort(
                    $cats,
                    array(
                        'term_id' => 'ASC',
                    )
                );

                /** * Filters the category that gets used in the %category% permalink token. * * @since 3.5.0 * * @param WP_Term $cat The category to use in the permalink. * @param array $cats Array of all categories (WP_Term objects) associated with the post. * @param WP_Post $post The post in question. */

function get_the_category_rss( $type = null ) {
    if ( empty( $type ) ) {
        $type = get_default_feed();
    }
    $categories = get_the_category();
    $tags       = get_the_tags();
    $the_list   = '';
    $cat_names  = array();

    $filter = 'rss';
    if ( 'atom' === $type ) {
        $filter = 'raw';
    }

    if ( ! empty( $categories ) ) {
        foreach ( (array) $categories as $category ) {
            
Home | Imprint | This part of the site doesn't use cookies.