Как удалить повторяющиеся столбцы на странице категории?

На странице категории подкатегории повторяются в точном поиске. Я добавил категории и подкатегории. У меня есть 3 категории уровня, т.е. чехлы для телефонов (родительский) -> Apple (подкатегория) -> iPhone X (подкатегория яблока).

Скриншот:

Изображение

<?php
{{ header }}
    <div id="product-category" class="container">
        <ul class="breadcrumb">
            {% for breadcrumb in breadcrumbs %}
                <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
            {% endfor %}
        </ul>
        <div class="row">
        {{ column_left }}
            {% if column_left and column_right %}
                {% set class = 'col-sm-6' %}
            {% elseif column_left or column_right %}
                {% set class = 'col-sm-9' %}
            {% else %}
                {% set class = 'col-sm-12' %}
            {% endif %}
            <div id="content" class="{{ class }}">
            {{ content_top }}
            <h2>{{ heading_title }}</h2>
                {% if thumb or description %}
                    <div class="row"> 
                    {% if thumb %}<div class="col-sm-2"><img src="{{ thumb }}" alt="{{ heading_title }}" title="{{ heading_title }}" class="img-thumbnail" /></div>
                    {% endif %}
                    {% if description %}<div class="col-sm-10">{{ description }}</div>
                    {% endif %}</div>
                    <hr>
                {% endif %}
            {% if categories %}
            <h3>{{ text_refine }}</h3>
                {% if categories|length <= 5 %}
                    <div class="row">
                        <div class="col-sm-3">
                            <ul>
                            {% for category in categories %}
                                <li><a href="{{ category.href }}">{{ category.name }}</a></li>
                            {% endfor %}
                            </ul>
                        </div>
                    </div>
                {% else %}
                <div class="row">
                    {% for category in categories|batch((categories|length / 4)|round(1, 'ceil')) %}
                    <div class="col-sm-3">
                        <ul>
                            {% for child in category %}
                                <li><a href="{{ child.href }}">{{ child.name }}</a></li>
                            {% endfor %}
                        </ul>
                    </div>
                    {% endfor %}
                </div>
                <br />
                {% endif %}
            {% endif %}
{% if products %}
<div class="row">
    <div class="col-md-2 col-sm-6 hidden-xs">
        <div class="btn-group btn-group-sm">
            <button type="button" id="list-view" class="btn btn-default" data-toggle="tooltip" title="{{ button_list }}"><i class="fa fa-th-list"></i></button>
            <button type="button" id="grid-view" class="btn btn-default" data-toggle="tooltip" title="{{ button_grid }}"><i class="fa fa-th"></i></button>
        </div>
    </div>
    <div class="col-md-3 col-sm-6">
        <div class="form-group"><a href="{{ compare }}" id="compare-total" class="btn btn-link">{{ text_compare }}</a>
    </div>
</div>
<div class="col-md-4 col-xs-6">
    <div class="form-group input-group input-group-sm">
        <label class="input-group-addon" for="input-sort">{{ text_sort }}</label>
        <select id="input-sort" class="form-control" onchange="location = this.value;">
            {% for sorts in sorts %}
                {% if sorts.value == '%s-%s'|format(sort, order) %}
                    <option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
                {% else %}
                    <option value="{{ sorts.href }}">{{ sorts.text }}</option>
                {% endif %}
            {% endfor %}
        </select>
    </div>
</div>
<div class="col-md-3 col-xs-6">
    <div class="form-group input-group input-group-sm">
        <label class="input-group-addon" for="input-limit">{{ text_limit }}</label>
        <select id="input-limit" class="form-control" onchange="location = this.value;">
            {% for limits in limits %}
                {% if limits.value == limit %}
                    <option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
                {% else %}
                    <option value="{{ limits.href }}">{{ limits.text }}</option>
                {% endif %}
            {% endfor %}
        </select>
    </div>
</div>
</div>
<div class="row"> 
    {% for product in products %}
        <div class="product-layout product-list col-xs-12">
            <div class="product-thumb">
                <div class="image"><a href="{{ product.href }}"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="img-responsive" /></a></div>
            <div>
            <div class="caption">
                <h4><a href="{{ product.href }}">{{ product.name }}</a></h4>
                <p>{{ product.description }}</p>
                {% if product.price %}
                    <p class="price"> 
                    {% if not product.special %}
                        {{ product.price }}
                    {% else %} 
                        <span class="price-new">{{ product.special }}</span> 
                        <span class="price-old">{{ product.price }}</span> 
                    {% endif %}
                    {% if product.tax %} 
                        <span class="price-tax">{{ text_tax }} {{ product.tax }}</span> 
                    {% endif %} 
                    </p>
                {% endif %}
                {% if product.rating %}
                    <div class="rating"> 
                    {% for i in 1..5 %}
                        {% if product.rating < i %} 
                            <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span> 
                        {% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
                        {% endif %}
    {% endfor %} 
</div>
{% endif %} 
</div>
<div class="button-group">
<button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
<button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
</div>
</div>
</div>
</div>
{% endfor %} </div>
<div class="row">
<div class="col-sm-12 text-left">{{ pagination }}</div>
{#  <div class="col-sm-6 text-right">{{ results }}</div> #}
</div>
{% endif %}
{% if not categories and not products %}
    <p>{{ text_empty }}</p>
    <div class="buttons">
        <div class="pull-right"><a href="{{ continue }}" class="btn btn-primary">{{ button_continue }}</a></div>
    </div>
{% endif %}
{{ content_bottom }}</div>
{{ column_right }}</div>
</div>
{{ footer }} 

person Debu    schedule 21.10.2018    source источник
comment
Пожалуйста, добавьте код шаблона.   -  person Marco    schedule 21.10.2018
comment
Я редактировал вопрос с добавленным кодом. Скопировано из шаблона продукта / категории. @ Marco   -  person Debu    schedule 21.10.2018
comment
Вам нужно поработать над отступами, я не могу легко сказать, где что, если заканчивается, не глядя на все. Вероятно, это то, что затрудняет вам наблюдение за тем, где что-то идет не так семантически. Таким образом, вам будет намного проще проверять, где заканчивается / начинается if, петли и т. Д. Занят, переживая это.   -  person Marco    schedule 21.10.2018


Ответы (1)


Ладно, это похоже на подходящую деталь.

{% if categories %}
  <h3>{{ text_refine }}</h3>
    {% if categories|length <= 5 %}
    <div class="row">
      <div class="col-sm-3">
        <ul>
          {% for category in categories %}
            <li><a href="{{ category.href }}">{{ category.name }}</a></li>
          {% endfor %}
        </ul>
      </div>
    </div>
    {% else %}
    <div class="row">
      {% for category in categories|batch((categories|length / 4)|round(1, 'ceil')) %}
      <div class="col-sm-3">
        <ul>
          {% for child in category %}
            <li><a href="{{ child.href }}">{{ child.name }}</a></li>
          {% endfor %}
        </ul>
      </div>
      {% endfor %}</div>
    <br />
    {% endif %}
  {% endif %}

Думаю, у вас есть еще триггеры, поскольку у вас более 5 категорий. Как видите, дочерний элемент в этой категории печатается вместо категории, которую вы пытаетесь активировать. Скорее удалите if / else и пропустите все категории. Каждый из ваших детей также подпадает под несколько категорий, следовательно, это дублирование.

{% if categories %}
  <h3>{{ text_refine }}</h3>
    <div class="row">
      <div class="col-sm-3">
        <ul>
          {% for category in categories %}
            <li><a href="{{ category.href }}">{{ category.name }}</a></li>
          {% endfor %}
        </ul>
      </div>
    </div>
  {% endif %}

Вероятно, это то, что вы хотите, или если вам нужна только первая категория с ее дочерними элементами:

{% if categories %}
  <h3>{{ text_refine }}</h3>
    <div class="row">
      <div class="col-sm-3">
        <ul>
          {% for child in category %}
            <li><a href="{{ child.href }}">{{ child.name }}</a></li>
          {% endfor %}
        </ul>
      </div>
    </div>
  {% endif %}
person Marco    schedule 21.10.2018
comment
Сделал отступ в моем коде в вопросе. Пытался добавить вам фрагмент кода, и после этого я очистил кеш темы с панели управления, но ничего не изменилось. - person Debu; 21.10.2018
comment
Могу я спросить, какую из них вы скопировали? - person Marco; 21.10.2018
comment
Я почему бы и нет. Первый. Найдите его ниже {% if категории%} ‹h3› {{text_refine}} ‹/h3› ‹div class = row› ‹div class = col-sm-3› ‹ul› {% для категории в категориях%} ‹ li ›‹a href={{ category.href }}› {{category.name}} ‹/a› ‹/li› {% endfor%} ‹/ul› ‹/div› ‹/div› {% endif% } - person Debu; 21.10.2018
comment
И вы говорите, что есть несколько столбцов? Цикла for больше нет, так что его быть не должно. - person Marco; 21.10.2018
comment
Я вот что смущает. Даже если я сделаю небольшое изменение в тексте, эта страница не будет отражена. Отключил кеш и на панели инструментов. - person Debu; 21.10.2018
comment
Вы уверены, что вызывается страница / шаблон? - person Marco; 21.10.2018
comment
Кажется, у вас установлено какое-то расширение ... так что вам также нужны обновления. - person K. B.; 21.10.2018