WordPress.org

Forums

[resolved] Retrieve _just_ the post category? (5 posts)

  1. bitbutter
    Member
    Posted 9 years ago #

    In the loop: I know there are functions to retrieve an html string with a link to the current posts category, but is there a function that will just return the category name as a string?

    thanks!

  2. MichaelH
    Member
    Posted 9 years ago #

  3. bitbutter
    Member
    Posted 9 years ago #

    michael: thanks for your reply. I was already using that function though, and was surprised that it returns a html link string instead of just the category name.

    $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_name;

    Echoes something like this:
    <li><a href=""> News</a></li>

    Instead of just News

  4. schulte
    Member
    Posted 9 years ago #

    Hmmm...just tried that function and it returns a string (the category only) for me...where did you use the function exactly?

  5. bitbutter
    Member
    Posted 9 years ago #

    thanks for yor help! it was a silly mistake by me.. i had put the variable in a routine that was adding the extra markup. [slaps forehead]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags