render_block_core_categories()


WordPressのrender_block_core_categories()関数は、カテゴリーリストを表示するためのコアブロックをレンダリングするために使用されます。

構文

render_block_core_categories( array $attributes, string $content, WP_Block $block );

引数の説明:

  • $attributes (array) — ブロックの属性(例: 表示オプション)
  • $content (string) — ブロックコンテンツ
  • $block (WP_Block) — ブロックインスタンス

例1: 基本的なカテゴリーリストの表示

デフォルト設定でカテゴリーリストを表示します。

echo render_block_core_categories( array(), '', null );

例2: ドロップダウン形式で表示

カテゴリーをドロップダウンメニューとして表示します。

echo render_block_core_categories( array('displayAsDropdown'=>true), '', null );

例3: 投稿数を含めて表示

各カテゴリーの投稿数を表示します。

echo render_block_core_categories( array('showPostCounts'=>true), '', null );

例4: 階層表示を無効化

カテゴリーの階層表示を無効にします。

echo render_block_core_categories( array('showHierarchy'=>false), '', null );

例5: 空のカテゴリーを非表示

投稿がないカテゴリーを表示しません。

echo render_block_core_categories( array('hideEmpty'=>true), '', null );

例6: 特定のカテゴリーのみ表示

指定したIDのカテゴリーのみ表示します。

echo render_block_core_categories( array('include'=>array(get_cat_ID('未分類'))), '', null );

例7: カスタムCSSクラスの追加

ブロックにカスタムクラスを追加します。

echo render_block_core_categories( array('className'=>'custom-categories'), '', null );

注意点

  • この関数は主にブロックエディターで使用されます
  • 直接呼び出すよりはブロックシステムを通して使用するのが適切です
  • 属性パラメータはブロックの設定と連動しています

関連機能: