Bricks 中文文档:bricks/frontend/render_loop

📄 原始资料  |  展开查看原始 JSON(bricks-frontend-render_loop.json){ “name”: “bricks/frontend/render_loop”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-frontend-render_loop/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/frontend/render_loop”, “descri…

📄 原始资料  |  展开查看原始 JSON(bricks-frontend-render_loop.json)
{
  "name": "bricks/frontend/render_loop",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-frontend-render_loop/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/frontend/render_loop",
  "description": {
    "en": "Filters the HTML output of a query loop iteration. This allows you to modify the content of each item rendered within a loop.",
    "zh": "修改 Bricks 中用于 WooCommerce 集成的小工具(widget)列表。"
  },
  "parameters": [
    {
      "name": "output",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The rendered HTML of the loop item.",
        "zh": "循环项的渲染 HTML。"
      }
    },
    {
      "name": "element",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "The element data array.",
        "zh": "元素数据数组。"
      }
    },
    {
      "name": "container",
      "type": "object",
      "type_zh": null,
      "description": {
        "en": "The container element instance managing the loop.",
        "zh": "管理循环的容器元素实例。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/frontend/render_loop', function( $output, $element, $container ) {\n    // Example: Wrap each loop item in a custom div\n    return '<div class=\"my-custom-loop-wrapper\">' . $output . '</div>';\n}, 10, 3 );"
}

前言

修改 Bricks 中用于 WooCommerce 集成的小工具(widget)列表。

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/frontend/render_loop', function( $output, $element, $container ) {
    // Example: Wrap each loop item in a custom div
    return '
' . $output . '
'; }, 10, 3 );

参数

  • $output (string):循环项的渲染 HTML。
  • $element (array):元素数据数组。
  • $container (object):管理循环的容器元素实例。

示例代码

筛选返回值

add_filter( 'bricks/frontend/render_loop', function( $output, $element, $container ) {
    // Example: Wrap each loop item in a custom div
    return '
' . $output . '
'; }, 10, 3 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/frontend/render_loop', function( $value, $output ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档