• Hi there
    when I use
    <?php the_category_ID(); ?>
    This always seems to print zero, regardless of the category I’m in or post type??
    Any Clues?

Viewing 13 replies - 1 through 13 (of 13 total)
  • @stevechamp: You do not mention what version you are using, but that function has been deprecated and does not return the correct value for the Category ID.
    I am not sure what you are trying to achieve, so a little more information would make things clear for everyone.
    Peace

    I managed to get it working in one of the nightlys with <?php the_category_ID ('true') ?>.

    Thread Starter stevechamp

    (@stevechamp)

    What I want to do is assign a css class to different category, so using:
    <div class="cat_<?php the_category_ID(); ?>">
    Is there another way to do this??

    Thread Starter stevechamp

    (@stevechamp)

    using version 1.0.2 by the way!

    I would try to adding the ‘true’ parameter to your function call and see if that solves your problem. I wold also suggest you give 1.2 a serious look.
    Development has been very good and teh new features are amazing.

    Thread Starter stevechamp

    (@stevechamp)

    Hi
    I’ve clean upgraded to 1.2 (seems a lot better)
    But I still have the same problem.
    Can anyone tell me why..
    <div class="post-<?php the_category_ID(); ?>">
    Only returns zero (“post-0”, etc) when my category ID’s are 1-4, and seem to work fine?
    Thanks

    Thread Starter stevechamp

    (@stevechamp)

    I found that above works in the category sections, but not index.
    So where cat=2 class=”post-2″
    But on index page I can only get “post-0”
    Is there a way to achieve different category numbers on the index page?

    did you try the ‘true’ thing? I’m confused. It was working for me in the nightly, but maybe it’s been taken out of the release candidate?

    Thread Starter stevechamp

    (@stevechamp)

    tried true

    Thread Starter stevechamp

    (@stevechamp)

    many thanks, but didn’t work for me
    outputs nothing?

    Steve,

    function the_category_ID($echo = true) {
    global $post;
    if ($echo)
    echo $post->post_category;
    else
    return $post->post_category;
    }

    this is the function, itself as it is in template-functions-category.php
    You can use it as you want to.

    Ummm…. I’m wondering if this still works now that there is multi-category capabilities (and sub cats to boot.)
    TG

    I hadn’t thought of that. My install was using an old database going right back to b2. Tables created in 1.0 or later very well might not include a value for post_category.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘category id problem’ is closed to new replies.