Forums

[resolved] howto show category name by ID (3 posts)

  1. piedro
    Member
    Posted 2 years ago #

    Hallo!

    I just want to show the name of my category with the ID=1
    within my template. So I tried:

    <h2><?php echo( get_category( 1 ) ); ?></h2>

    But that gives me the following error:

    Catchable fatal error: Object of class stdClass could not be converted to string in ...

    I understand that get_category delivers in the wrong format but have no clue what to do to get the screen printout of the name.

    any help appreciated,
    thx,
    piedro

  2. peterwongpp
    Member
    Posted 2 years ago #

    This might help you: get_category

    get_category return an object as default.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    <?php
    $cat=1;
    $yourcat = get_category($cat);
    if ($yourcat) {
    echo '<h2>' . $yourcat->name . '</h2>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic