• Help! I need somebody. Help! Not just anybody. Help! I need some PHP. Help! ??

    I’m probably making a very silly mistake, but I could really use someone to point it out.

    I started with code from the Codex (here), and reworked it to store the cat id in a variable (if the current category is top-level) or the parent cat id (if the current category is a sub-category). Previously the code printed out the cat/parent cat.

    However, for some reason, everytime I use the variable, I get the cat/parent cat URI instead of its ID number.

    Just what the heck did I do wrong?

    Here’s the script running in header.php:

    <?
    // CATEGORY SNIFFER Begin
    $category = get_category($cat);

    // If category is parent, list it
    if ($category->category_parent == 0) {
    $category = get_category_link($cat); // store what would be printed in the $category variable
    $category->category_parent = $cat;
    } else {
    // If category is not parent, list parent category
    $parent_category = get_category($category->category_parent);
    $category = get_category_link($parent_category->cat_ID);
    }
    // $category now holds whatever would have been printed

    // CATEGORY SNIFFER End
    ?>

    And here’s me calling it in category.php (this is a test, don’t blast me for using a font tag instead of CSS ?? ):

    <font size="4" color="#FF0000"><?php print($category); ?></font>

    Using that call, I get https://blog/category instead of the category ID.

Viewing 4 replies - 1 through 4 (of 4 total)
  • 1) font tags are so last century
    2) you call get_category_link right at the end – I think the function name says exactly what it does…

    Thread Starter iamPariah

    (@iampariah)

    While I appreciate your help, it doesn’t actually tell me how to make this work. I see that I’ve inadvertantly left in get_category_link, but to what should I change it to return the category ID instead?

    *resists the urge to “blast” you for using <font>*

    Is this for posts or for category archives?

    Thread Starter iamPariah

    (@iampariah)

    As I said in my first post, I used <font> for testing only.

    It’s for both category archives and posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help PHP cat_id coming out cat url’ is closed to new replies.