product.tpl中的图像仅在某些类别中

时间:2019-07-04 11:47:14

标签: php prestashop prestashop-1.7

我在prestashop站点中创建了product.tpl文件中的规则,以仅显示特定类别的图像。给定涉及的类别数量(显示图像的类别),我选择在所有类别中显示图像,除了某些类别。我已将此代码插入我的产品页面:

{if $ category-> id! = 78 AND $ category-> id! = 64 AND $ category-> id! = 29 AND $ category-> id! = 91 AND $ category-> id! = 92 AND $ category- > id! = 93 AND $ category-> id! = 94 AND $ category-> id! = 95 AND $ category-> id! = 102 AND $ category-> id! = 17 AND $ category-> id! = 71 AND $ category-> id! = 106 AND $ category-> id! = 107 AND $ category-> id! = 109 AND $ category-> id! = 72 AND $ category-> id! = 101 AND $ category-> id! = 96 AND $ category-> id! = 97 AND $ category-> id! = 75 AND $ category-> id! = 69 AND $ category-> id! = 100 AND $ category-> id! = 73 AND $ category-> id! = 70 AND $ category-> id! = 65 AND $ category-> id! = 80 AND $ category-> id! = 81 AND $ category-> id! = 82 AND $ category-> id ! = 84 AND $ category-> id! = 83 AND $ category-> id! = 79 AND $ category-> id! = 110 AND $ category-> id! = 79 AND $ category-> id! = 111 AND $ category-> id! = 79 AND $ category-> id! = 112 AND $ category-> id! = 79 AND $ category-> id! = 113 AND $ category-> id! = 79 AND $ category-> id! = 66 AND $ category-> id! = 79 AND $ category-> id! = 85 AND $ category-> id! = 79 AND $ category-> id! = 86 AND $ category-> id! = 79 AND $ category-> id! = 87 AND $ category-> id! = 79 AND $ category-> id! = 90 AND $ category-> id! = 79 AND $ category-> id! = 67 AND $ category-> id! = 79 AND $ category-> id! = 68 AND $ category-> id! = 79 AND $ category-> id! = 74 AND $ category-> id! = 79 AND $ category-> id! = 104 AND $ category-> id! = 79 AND $ category-> id ! = 108 AND $ category-> id! = 79 AND $ category-> id! = 15 AND $ category-> id! = 79 AND $ category-> id! = 340 AND $ category-> id! = 1457 AND $ category-> id! = 1497 AND $ category-> id! = 1498 AND $ category-> id! = 1499 AND $ category-> id! = 1417 AND $ category-> id! = 1501 AND $ category-> id! = 1524}
          <Div> IMAGE </ div>

此模式有效,但是它消耗了服务器上太多的资源,我该如何以一种更简洁的方式来做同样的事情?

谢谢

2 个答案:

答案 0 :(得分:2)

表示它不会消耗太多资源,一种更清洁的方式是:

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

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

即使我读到{php}使用已被弃用

已更新

{php}标签以来,您可以使用以下标签:

{assign var='excluded_categories_ids' value=[78, 64, ...]}

答案 1 :(得分:0)

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

{assign var='excluded_categories_ids' value=[78, 64, 29, 91, 92, 93 ...]}
{if (!in_array($category->id, $excluded_categories_ids))}
    <div>Image</div>
{endif}