• All I want to do is echo the name of the category without any links, uls, or css classes. Maybe I’m being stupid and not seeing what’s in front of my nose, but I can’t find the function for this anywhere and I’m getting desperate. Version 1.2 .TIA.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Don’t know exactly how you want to use it but try:
    <?php $categories = get_the_category(); echo $categories[0]->cat_name; ?>

    If this is helpful at all:
    One might desire to have the Category name show up on a category specific page
    <?php wp_title () ?> will output the page name, as in the browser title bar it’d look like:
    >> Category Name
    Not exactly what one might want to output, but it works.
    That code will output the name of every page. Plain index.php has no name. But all category, month, and single pages have names. (and then search pages return no name)
    To only output the title on category pages use an if statement:
    <?php if ($cat) { ?><?php wp_title () ?><?php } ?>
    to output on category and monthly pages use an if not single statement like:
    <?php if (!$single) { ?><?php wp_title () ?><?php } ?>
    Monthly pages show this kind of title:
    >>Year >> Month Name
    example:
    >> 2004 >> June
    —–
    I’d be interested in a way to get the titles of the pages without the duhickies, so another code to pull the actual category name of the page, for instance, to display on the page.

    Thread Starter Anonymous

    Beel’s solution worked. I’d never have figured that code out for myself, thanks! Kind of surprised there isn’t a simpler way of doing it but hey, it works, why quibble?

    Well, this is happening becouse search windows doesn`t have any category name. How to change, that search window also would have a category, “search” for example, because in other way there is systax error.

    I tested it on my blog and did not get that error. I guess about now a link would be helpful.

    Thread Starter Anonymous

    I don’t see why it would interfere with the search feature unless you had actually been messing with the template functions. I just put the code in index.php in place of <?php the_category ?> and it worked fine.

    The problem occures only when nothing is found. You can see it here: https://www.webmag.tk
    I put the code above the categories, to display a categorie in witch you are curretnly in.
    Type something like “asd” in the search row, and see what`s happening with category display. But if you type some text form any post, search finds it, and displays first category with no problem.

    I must be a little confused and it doesn’t help that I am limited to one language. Where are you using my hack as your categories all appear to be links. I again tested on my blog and upon “Sorry, no posts matched your criteria” I did not get any errors.

    Thread Starter Anonymous

    Oh, right, now I get it… you must be displaying the category outside the loop. My category is right next to the entry, so no entry = no category. Sounds like you would need a conditional statement to display something else in place of the category code when ?s is in the querystring.

    ksp: I first thought you wanted it in the loop, since you don’t it does not really work – it just pulls from the last entry in the loop to display the category – which, as you can see, does not work for “Home”. You are not using permalinks so a simple thing to do would be to build what you want to return based upon the category id. For starters, something like:
    <?php if ($cat==1) echo “Home”; elseif ($cat==15) echo “Web”; else echo “Home”; ?>
    You will have to add the other $cat/category names.

    That worked, but not for posts. If inside post, the category shows “HOME”.
    Is there a parameter witch affects posts category display?

    Thanks for the help Bill.
    Thing is I want single post category do be displayed also. Now, using $single or !$single every post gets a same “category” ??

    Yeah, I know – that is the problem with doing it out of the loop. I can’t visualize how to get the category of the single post when not in the loop. That is why I just have it echo “Single Post” and not a category name. As best I can tell, you’d have to do a db query to get the category.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘how do I echo category names without links or othe’ is closed to new replies.