Help PHP cat_id coming out cat url
-
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.
- The topic ‘Help PHP cat_id coming out cat url’ is closed to new replies.