Php 在Virtuemart中检测产品的多个类别ID
我们有这样一个声明,检查产品是否属于该类别,然后显示一些HTML,但问题是该产品被分为多个类别,例如时装、男士和销售,因此:Php 在Virtuemart中检测产品的多个类别ID,php,joomla,joomla2.5,joomla1.5,virtuemart,Php,Joomla,Joomla2.5,Joomla1.5,Virtuemart,我们有这样一个声明,检查产品是否属于该类别,然后显示一些HTML,但问题是该产品被分为多个类别,例如时装、男士和销售,因此: fashion category id is 16 men category id is 12 and sale category is 64 为了添加一些额外的HTML,我试图确定产品是否也在分类销售中,但只有当我设置if($this->product->virtuemart\u category\u id==16)时,它才能工作。 仅识别第一类的语句 if($thi
fashion category id is 16
men category id is 12
and sale category is 64
为了添加一些额外的HTML,我试图确定产品是否也在分类销售中,但只有当我设置if($this->product->virtuemart\u category\u id==16)时,它才能工作。
仅识别第一类的语句
if($this->product->virtuemart_category_id == 64){
echo 'your Custom HTML';
}
else{
//nothing
}
如何确定此产品是否也属于销售类别?您可以使用定义为
|
的或运算符,如下所示:
$cat_id = $this->product->virtuemart_category_id;
if ($cat_id == 16 || $cat_id == 64) {
echo 'your Custom HTML';
}
else {
// do nothing
}
这检测类别是时尚还是销售
如果要检测另一个类别,只需添加| |$cat\u id==id
,其中id是类别id
希望这有帮助试试这个
在VM中,您可以为一个产品添加多个类别
它将以如下所示的数组形式给出类别ID
print_r($this->product->categories );
因此,如果您有需要自定义样式的预定义类别列表
if(in_array(16,$this->product->categories) || in_array(64,$this->product->categories) || in_array(12,$this->product->categories)){
echo 'your styles';
}
要获得更好的方法,您可以尝试以下方法
$custom_cats = array(12,16,64);//your custom categories that required additional styles
$current_product_cats = $this->product->categories;
$checkstatus = array_intersect($custom_cats , $current_product_cats);
if(sizeof($checkstatus)>0){ // check your first array element found in second array
echo 'your custom styles';
}
希望它能起作用。它能起作用,但不幸的是,它没有看到产品属于64类。我不知道为什么,但产品很可能只有一个id类别。我认为在VirtueMart中,一个产品只能分配一个类别,而不能分配多个类别