WordPress.org

Forums

Need help category title in single post template (5 posts)

  1. KanIshigami
    Member
    Posted 10 years ago #

    When I use the function single_cat_title() inside the single.php template, it returns a null value. I'm using this to include a php code relative to post category.

    It's like this:

    <?php
    $categoria = single_cat_title('',false);
    $categoria_out = dirify($categoria);
    ?>

    This code work perfectly in category template, but in single post template I have this problem - single_cat_title() returns a null value.

    How I can display the category name in single.php template outside The Loop?

  2. Kafkaesqui

    Posted 10 years ago #

    Try out this bit of PHP querying:

    <?php
    global $post;
    $my_cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories, $wpdb->post2cat WHERE cat_ID = category_id AND post_id = $post->ID");
    echo strip_tags($my_cat_name);
    ?>

  3. KanIshigami
    Member
    Posted 10 years ago #

    I'll test this code... Thank you very much Kafkaesqui

  4. lx23
    Member
    Posted 9 years ago #

    It works. And it also works in the category template. I still wonder if there's something built in...

  5. MrFlora
    Member
    Posted 9 years ago #

    AWESOME. #1 worked wonderfully.

    Thanks!

    http://www.goculver.com

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.