WordPress.org

Ready to get started?Download WordPress

Forums

Help me, how i can echo a category of a single post in single.php??? (3 posts)

  1. joint77
    Member
    Posted 1 year ago #

    Hi i've a big problem, what's the codex to echo a category of a single post?

    For example, i've a post with category "ATTIVITA' ANNUALI" how i can echo the category (used a variable) in file single.php

    Thanks, Ale.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

  3. joint77
    Member
    Posted 1 year ago #

    Thanks, if i use <?php echo wp_get_post_categories( $post_id, $args ); ?> display me the string "array".

    I must add this function in function.php to meke this???

    function wp_get_post_categories( $post_id = 0, $args = array() ) {
    $post_id = (int) $post_id;

    $defaults = array('fields' => 'ids');
    $args = wp_parse_args( $args, $defaults );

    $cats = wp_get_object_terms($post_id, 'category', $args);
    return $cats;
    }

    LINK

Topic Closed

This topic has been closed to new replies.

About this Topic