如何检查当前猫是否在数组内并且 IF 是父级
How to check if current cat is inside an array AND IF is parent
我有一个名为 $best_cats
的全局
global $best_cats;
$best_cats = array(8,31,51,102,217,218);
现在我需要检查当前猫是否在数组内部,如果当前猫是父猫。
我正在尝试这种方式,但没有用。我做错了什么,我该怎么做?
<?php
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) { ?>
//category is inside of the array and is a parent cat
<?php } else { ?>
//category is not inside the array and It's not a parent either
<?php } ?>
你好像忘记了 global
<?php
global $best_cats;
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) {
//category is inside of the array and is a parent cat
} else {
//category is not inside the array and It's not a parent either
}
我有一个名为 $best_cats
global $best_cats;
$best_cats = array(8,31,51,102,217,218);
现在我需要检查当前猫是否在数组内部,如果当前猫是父猫。
我正在尝试这种方式,但没有用。我做错了什么,我该怎么做?
<?php
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) { ?>
//category is inside of the array and is a parent cat
<?php } else { ?>
//category is not inside the array and It's not a parent either
<?php } ?>
你好像忘记了 global
<?php
global $best_cats;
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) {
//category is inside of the array and is a parent cat
} else {
//category is not inside the array and It's not a parent either
}