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

自定义TypoScript轮播滑块排序异常求助:如何按指定PID顺序排列?

Absolutely, you can enforce a specific order for your carousel slider—let’s break down two reliable solutions to match your defined PID sequence.

The Quick Fix: Use MySQL's FIELD() Function

Your current select.orderBy = sorting only sorts content within each individual page (PID), which is why the overall slider order feels random. To force results to follow your exact PID list, leverage MySQL’s FIELD() function in your orderBy clause. This tells the database to return rows in the exact order you specify the PIDs.

Update each of your CONTENT objects to include this modified orderBy:

lib.contentSlider = COA
lib.contentSlider {
  10 = CONTENT
  10 {
    table = tt_content
    select.where = colPos = 1
    select.languageField = sys_language_uid
    select.pidInList = {$slider_site_ids}
    # This line enforces your PID order
    select.orderBy = FIELD(pid, {$slider_site_ids})
  }
  10.wrap = <div class="slider-img-cnt">|</div>

  # Repeat this select.orderBy line for 20, 30, 40, 50, 60 CONTENT objects
  20 = CONTENT
  20 {
    table = tt_content
    select.where = colPos = 10
    select.languageField = sys_language_uid
    select.pidInList = {$slider_site_ids}
    select.orderBy = FIELD(pid, {$slider_site_ids})
  }
  20.wrap = <div class="content-left fl-left">|</div>

  # ... (keep your existing wrap settings for 30-60, just add the orderBy line)
}
lib.contentSlider.wrap = <article>|</article>

This works because FIELD(pid, 1359,1348,...) prioritizes rows where pid matches the first value in your list, then the second, and so on.

The Flexible Fix: Use a LOOP (TypoScript's "For Each" Equivalent)

If you want even more control (e.g., ensuring each PID’s content is grouped as a single slider item), use a LOOP to iterate directly over your PID list. This guarantees the order matches exactly what you defined in slider_site_ids.

First, make sure your PID list is accessible to the loop, then build each slider item per PID:

# First, register your PID list (optional but clean)
page.9 = TEXT
page.9.data = {$slider_site_ids}
page.9.register = slider_site_ids

# Now build the slider with a LOOP
lib.contentSlider = LOOP
lib.contentSlider {
  data = register:slider_site_ids
  split {
    token = ,
    cObjNum = 1
    1 = COA
    1 {
      # Content for colPos 1 (image)
      10 = CONTENT
      10 {
        table = tt_content
        select.where = colPos = 1
        select.languageField = sys_language_uid
        select.pidInList = {field:current}
        select.orderBy = sorting
      }
      10.wrap = <div class="slider-img-cnt">|</div>

      # Content for colPos 10 (left content)
      20 = CONTENT
      20 {
        table = tt_content
        select.where = colPos = 10
        select.languageField = sys_language_uid
        select.pidInList = {field:current}
        select.orderBy = sorting
      }
      20.wrap = <div class="content-left fl-left">|</div>

      # Add colPos 20, 30, 40, 50 content here using the same pattern
      30 = CONTENT
      30 {
        table = tt_content
        select.where = colPos = 20
        select.languageField = sys_language_uid
        select.pidInList = {field:current}
        select.orderBy = sorting
      }
      30.wrap = <div class="content-right fl-right">|</div>

      # ... (repeat for 40,50,60 with their respective wraps)
    }
    # Wrap each PID's content as a single slider item
    1.wrap = <article>|</article>
  }
}

This approach treats each PID as a separate slider entry, so the order will perfectly mirror your slider_site_ids list.

Key Notes

  • For the FIELD() method: Ensure your {$slider_site_ids} constant has no spaces between commas (e.g., 1359,1348,... not 1359, 1348,...), otherwise the function won’t work correctly.
  • Both methods work in all modern TYPO3 versions (TYPO3 9 LTS and above).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:09:40