WordPress.org

Ready to get started?Download WordPress

Forums

category id problem (14 posts)

  1. stevechamp
    Member
    Posted 10 years ago #

    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?

  2. Laughinglizard
    Member
    Posted 10 years ago #

    @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

  3. WillM
    Member
    Posted 10 years ago #

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

  4. stevechamp
    Member
    Posted 10 years ago #

    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??

  5. stevechamp
    Member
    Posted 10 years ago #

    using version 1.0.2 by the way!

  6. Chris J. Davis
    Member
    Posted 10 years ago #

    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.

  7. stevechamp
    Member
    Posted 10 years ago #

    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

  8. stevechamp
    Member
    Posted 10 years ago #

    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?

  9. WillM
    Member
    Posted 10 years ago #

    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?

  10. stevechamp
    Member
    Posted 10 years ago #

    tried true

  11. stevechamp
    Member
    Posted 10 years ago #

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

  12. carthik
    Member
    Posted 10 years ago #

    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.

  13. TechGnome
    Moderator
    Posted 10 years ago #

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

  14. WillM
    Member
    Posted 10 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.