Yet another category_ID how-to thread (1 post)

  1. gazouteast
    Posted 5 years ago #

    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?



Topic Closed

This topic has been closed to new replies.

About this Topic