block_core_list_render()


WordPressの関数block_core_list_render()は、ブロックエディターでリストをレンダリングするために使用されます。この関数は、指定されたリストの項目をHTMLリストとして表示します。

構文

block_core_list_render( array $attributes );
  • $attributes (array) — リストの属性。リストの内容やその他の設定を定義する配列。

例1: 単純なリストのレンダリング

この例では、単純なリストをレンダリングします。

<?php
$attributes = array(
    'items' => array('項目1', '項目2', '項目3'),
);
echo block_core_list_render( $attributes );
?>

例2: 番号付きリストのレンダリング

番号付きリストを表示するための例です。

<?php
$attributes = array(
    'items' => array('項目1', '項目2', '項目3'),
    'ordered' => true,
);
echo block_core_list_render( $attributes );
?>

例3: 空のリストの表示

空のリストをレンダリングする例です。

<?php
$attributes = array(
    'items' => array(),
);
echo block_core_list_render( $attributes );
?>

例4: リストアイテムにリンクを追加

リストアイテムにリンクを追加して表示する例です。

<?php
$attributes = array(
    'items' => array(
        '<a href="https://example.com">項目1</a>',
        '<a href="https://example.com">項目2</a>',
    ),
);
echo block_core_list_render( $attributes );
?>

例5: リストアイテムにカスタムクラスを追加

リストアイテムにカスタムクラスを追加する例です。

<?php
$attributes = array(
    'items' => array(
        '<span class="custom-class">項目1</span>',
        '<span class="custom-class">項目2</span>',
    ),
);
echo block_core_list_render( $attributes );
?>

注意点:

  • ordered属性が指定されていない場合、リストはデフォルトで無番号リストとしてレンダリングされます。
  • items配列は空でない場合、リストは正常にレンダリングされますが、空の配列が渡された場合、リストは表示されません。
  • HTMLタグがリストアイテムに含まれている場合、それらはHTMLとしてレンダリングされます。

関連機能: