Support » Plugins » Yet another category_ID how-to thread

  • Simple question –

    Outside (repeat OUTSIDE) the loop, and INSIDE a widget, I want to get the category ID number – simply and easily.

    What I want to code will have the following structure and be used in a text widget –

    if is_single() {
    global $post
    $cat = get_the_category[0]($post)
    echo another_function($cat)
    else if_category()
    echo another_function(cat_ID)

    All seems simple enough? Except the codex has NO answer that works. I’ve also spent hours scouring the forums (found plenty of threads asking a very similar question – all closed without answers or solutions).

    Every supposed solution I have seen involves using a ” -> ” in the code somewhere, and when I try it OUTSIDE the loop and INSIDE a widget it gets read as being the closing tag to a ” <!– ” comment opener, and all the php after the -> then displays as text output in the widget zone.

    (Server is PHP 5.2.6, MySQL 5, Apache 2.2, running WP 3.0.2 single site)

    So, can anyone tell me how to obtain the category id as an integer to assign it to a variable to use within another function’s invocation?



  • The topic ‘Yet another category_ID how-to thread’ is closed to new replies.