You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在collection.rain中实现4级分类缩略图展示?

It sounds like your current template is only set up to render thumbnails up to the 3rd category level, and you need to extend it to show 4th-level items (like the individual exhibitions under /exhibitions/past/2019/) on their parent 3rd-level page. Let's walk through how to fix this:

First, Understand the Hierarchy

Your structure looks like this:

  • Level 1: exhibitions
  • Level 2: past
  • Level 3: 2019 (the page you want to show thumbnails on)
  • Level 4: Individual exhibitions (e.g., February-March, which already has images attached)

Why Your Previous Code Didn't Work

The {% for sub in subsubCat.subs %} loop likely failed because subsubCat isn't the correct variable referencing the current 3rd-level category (in this case, 2019). You need to target the current category's direct children (the 4th-level items) instead.

Step-by-Step Fix in collection.rain

  1. Open your collection.rain template file
  2. Locate the <!-- 2nd/3rdlevel --> section of code
  3. Add the following block inside this section (place it where you want the 4th-level thumbnails to appear on the 3rd-level page):
<!-- Display 4th-level category thumbnails on 3rd-level pages -->
{% if currentCat.level == 3 and currentCat.subs is not empty %}
  <div class="category-thumbnails">
    {% for childCat in currentCat.subs %}
      <!-- Only render if the 4th-level category has an image attached -->
      {% if childCat.image %}
        <div class="thumbnail-item">
          <a href="{{ childCat.url }}">
            <img src="{{ childCat.image.url }}" alt="{{ childCat.name }}" />
            <span class="thumbnail-label">{{ childCat.name }}</span>
          </a>
        </div>
      {% endif %}
    {% endfor %}
  </div>
{% endif %}

Key Adjustments to Match Your Template

  • If your template uses a different variable name for the current category (e.g., collection instead of currentCat), replace currentCat with that variable.
  • Double-check the image field name: if your categories store thumbnails under thumbnail instead of image, update childCat.image to childCat.thumbnail.
  • Tweak the HTML classes (category-thumbnails, thumbnail-item) to match your site's existing CSS styling so the thumbnails look consistent with other levels.

Test the Change

After saving the template, visit the 2019 past exhibitions page—you should now see thumbnails for all 4th-level exhibitions under 2019, just like how lower-level pages show their children.

内容的提问来源于stack exchange,提问作者Outer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:19:39