WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_category_ID does not work.. (8 posts)

  1. Anonymous
    Unregistered
    Posted 10 years ago #

    <?php echo the_category_ID() ?> does not work on my blog... It always comes out as zero. Regardless if I have the "echo" in there or not, it always comes out as 0 ... I was using it for category images. But on all the old posts I made that had been converted from b2, it works... >_< Help here?

  2. shelleyp
    Member
    Posted 10 years ago #

    This is a known problem. Check the WPBug page on the wiki, http://wiki.wordpress.org/WPBugs. Some people have came up with a workaround, but this function is no longer working, and rumor has it, no longer supported.

  3. andrew_h
    Member
    Posted 10 years ago #

    That link does not reveal much :-). I would appreciate more info on this subject too - presumably there is a way of retreiving category ('s) for each post.
    Andrew

  4. shelleyp
    Member
    Posted 10 years ago #

    The link ended up with a period in it and should be http://wiki.wordpress.org/WPBugs - Look down the page for 1.2 frequent problems & bugs. This is one of them.
    Previous forum entries on this at http://wordpress.org/support/index.php?action=vthread&forum=3&topic=5757&page=0
    http://wordpress.org/support/3/6368
    http://wordpress.org/support/3/5287
    And if you search on the function name, I think you'll find other threads.
    Supposedly there might be a 1.2.1 branch, and this might be fixed in it. And a suggestion has been made to use get_the_category instead.

  5. Anonymous
    Unregistered
    Posted 10 years ago #

    I came up with a short workaround for this bug bear in mind I don't understand the whole wordpress system so if my code is sloppy don't get on my case. just put the following code in your template-functions file:
    function this_cat_id($seperator = '') {
    $categories = get_the_category();
    $i = 0;
    foreach ($categories as $category) {
    $category->cat_name = stripslashes($category->cat_name);
    if (0 < $i) echo $seperator . ' ';
    $output = $category->category_id;
    ++$i;
    }
    return($output);
    }

  6. Anonymous
    Unregistered
    Posted 10 years ago #

    I've looked at that code provided above and I'd say it's doing too much work... my solution is:

    (insert at end of wp-includes/template-functions-category.php)
    function print_cat_id()
    {
    $categories = get_the_category();
    foreach ($categories as $category)
    {
    echo $category->category_id;
    break;
    }
    }

    This prints the first category (as stored in the WP database). I figure if you want it to print a list of category IDs it's a different question, but this is what works as a replacement for the_category_id imho
    -- Karan

  7. Anonymous
    Unregistered
    Posted 10 years ago #

    dunno why that took so long for someone to post.

  8. edgy
    Member
    Posted 10 years ago #


    <?= $_GET['cat']?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.