Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php product.tpl中的图像仅适用于某些类别_Php_Prestashop_Prestashop 1.7 - Fatal编程技术网

Php product.tpl中的图像仅适用于某些类别

Php product.tpl中的图像仅适用于某些类别,php,prestashop,prestashop-1.7,Php,Prestashop,Prestashop 1.7,我在prestashop网站的product.tpl文件中创建了一条规则,只显示特定类别的图像。考虑到涉及的类别(显示图像的类别)的数量,我选择在所有类别中显示图像,但在某些类别中除外。我已在我的产品页面中插入此代码: {如果$category->id!=78和$category->id!=64和$category->id!=29和$category->id!=91和$category->id!=92和$category->id!=93和$category->id!=94和$categegory

我在prestashop网站的product.tpl文件中创建了一条规则,只显示特定类别的图像。考虑到涉及的类别(显示图像的类别)的数量,我选择在所有类别中显示图像,但在某些类别中除外。我已在我的产品页面中插入此代码:

{如果$category->id!=78和$category->id!=64和$category->id!=29和$category->id!=91和$category->id!=92和$category->id!=93和$category->id!=94和$categegory->id!=95和$categegegegory->id!=102和$categegegegegegory->id!=17和$categegegegegegory->id!=71和$categegegegegegory->id!=106和$c类别->id!=109和$category->id!=72和$category->id!=101和$category->id!=96和$category->id!=75和$category->id!=69和$category->id!=100和$category->id!=70和$categegory->id!=65和$categegegory->id!=80和$categegegory->id!=81和$categegory->id!=82和$category->id!=84和$category->id!=83和$category->id!=110和$category->id!=79和$category->id!=111和$category->id!=112和$category->id!=79和$category->id!=113和$category->id!=79和$category->id!=66和$category->id!=79和$category->id!=85和$category->id!=79和$category->id!=86和$category->id!=79和$category->id!=90和$category->id!=79和$category->id!=67和$category->id!=68和$category->id!=79和$category->id!=74和$类别->id!=79和$category->id!=104和$category->id!=79和$category->id!=79和$category->id!=15和$category->id!=79和$category->id!=1457和$category->id!=1498和$category->id!=1499和$category->id!=1417和$category->id!=1501和$category->id!=1524}
形象
这种模式可以工作,但它消耗了服务器上太多的资源,我如何以更干净的方式做同样的事情


谢谢

说它不会消耗那么多资源,一种更干净的方法是:

{php}
$excluded_categories_ids = [78, 64, ...];
{/php}

{if (!in_array($category->id, $excluded_categories_ids))}
    <div></div>
{endif}

说它不消耗那么多资源,一个更干净的方法是:

{php}
$excluded_categories_ids = [78, 64, ...];
{/php}

{if (!in_array($category->id, $excluded_categories_ids))}
    <div></div>
{endif}

必须在变量中添加所有排除的类别,然后对其进行测试:

{assign var='excluded_categories_ids' value=[78, 64, 29, 91, 92, 93 ...]}
{if (!in_array($category->id, $excluded_categories_ids))}
    <div>Image</div>
{endif}
{assign var='excluded_categories_id'value=[78,64,29,91,92,93…]
{如果(!在数组中($category->id,$excluded\u categories\u id))}
形象
{endif}

您必须在变量中添加所有排除的类别,然后对其进行测试:

{assign var='excluded_categories_ids' value=[78, 64, 29, 91, 92, 93 ...]}
{if (!in_array($category->id, $excluded_categories_ids))}
    <div>Image</div>
{endif}
{assign var='excluded_categories_id'value=[78,64,29,91,92,93…]
{如果(!在数组中($category->id,$excluded\u categories\u id))}
形象
{endif}

要省略已弃用的{php}的用法,可以使用组合{assign var='excluded_categories_ids'value=[78,64]}来定义它。要省略已弃用的{php}的用法,可以使用组合{assign var='excluded_categories_ids'value=[78,64]}来定义它非常感谢。使用此方法可以插入这么多类别ID而不影响系统吗?非常感谢。使用此方法可以插入这么多类别ID而不影响系统吗?