Category ID or the eternal new question never resolved ? (6 posts)

  1. HapaxLegomen
    Posted 10 years ago #


    I need the Category_ID in a loop to make conditionnal conditions and the function Category_ID is deprecated. So I have search a lot for the good method. I have found a get_the_category whitch is not working for me...

    I'm on WP1.5.2, I just want to obtain the cat ID of the current post, it's possible I'm a little dummy but... I don't succed and Wiki, Codex and forum give opposite informations.

    Is there someone who know the truth about it (the contemporary truth) ? And how to make ?

  2. Ment0r
    Posted 10 years ago #

    it's not possible. lol ...

    tried this a while back and wade thru every single category function, nothing.. there was once a "the_category_id" but it has deprecated.. for whatever reason. Only way to get it is thru hacking a bit..

    it's strange, isn't it?

  3. Beel
    Posted 10 years ago #

    Posts can be in multiple categories so the old method no longer worked properly. Will some variation of the example "replacement" on http://codex.wordpress.org/Template_Tags/the_category_ID not work for you?

  4. HapaxLegomen
    Posted 10 years ago #

    It's totally unbelievable. If you can't have the current cat ID, how do you make conditions if ?????!

    I have only 6 root category (no child). I absolutely need which category is current in my "single template". When I say absolutely, it's absolutely, because when it is a category, you have something display, and another, another display.

    I can't ask my author to use templates for each post ! And templates won't solve the problem when there is are if for an unique category...

    I made this so easely with b2 that I couldn't imagine I won't be able with WP ! How will I do ??? It's not a bug, it's a structural vice.

  5. HapaxLegomen
    Posted 10 years ago #

    Sorry, I have made a error in my code and

    foreach((get_the_category()) as $cat) {
    echo $cat->cat_ID . ' ';
    } ?>

    works for me ! :-)
    Always be carefull before crying too much... :-X

  6. HapaxLegomen
    Posted 10 years ago #

    Euuuh, always me...

    I use

    foreach((get_the_category()) as $cat)

    and after in my simgle template, I use a very basic if condition :

    if ($cat != 1)
    {echo 'test';}
    {echo '';}

    And my condition doesn't work... ?? Is there some technical specification about this way of catching cat ID to explain this ?
    I don't see the smallest error in my nano-code.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.