How to show category in page title?

Discussion in 'WordPress' started by dreteh, Feb 27, 2010.

  1. #1
    Hi,

    I know you can call wp_title() to display post title, but can I display category in the post title? I was playing around with single_cat_title(), but no luck. Anyone knows? Thank you.
     
    dreteh, Feb 27, 2010 IP
  2. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Ok, I understand why single_cat_title() doesn't work. Because a post can belongs to one or more categories( I guess). So, here is my solution:

    I made a function in the Header.php:

    function first_cat_title()
    {
    $cats = get_the_category();
    $firstCat = $cats[0]->cat_name;

    echo $firstCat;
    }

    So it will always display the first category name =)
     
    dreteh, Feb 27, 2010 IP