render_block_core_post_featured_image()


WordPressのrender_block_core_post_featured_image()関数は、投稿のアイキャッチ画像を表示するためのコアブロックをレンダリングするために使用されます。この関数は、ブロックエディター内でアイキャッチ画像を表示する際に役立ちます。

構文

render_block_core_post_featured_image( array $block );
  • $block(array) — ブロックの属性や設定を含む配列。

例1: 基本的なアイキャッチ画像の表示

この例では、投稿のアイキャッチ画像を表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image' ) );

例2: カスタムサイズのアイキャッチ画像

アイキャッチ画像のサイズをカスタマイズして表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'sizeSlug' => 'medium' ) ) );

例3: 特定の投稿のアイキャッチ画像を表示

特定の投稿IDを使用してアイキャッチ画像を表示します。

$post_id = get_the_ID(); echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'postId' => $post_id ) ) );

例4: アイキャッチ画像にクラスを追加

アイキャッチ画像にカスタムクラスを追加して表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'className' => 'custom-image-class' ) ) );

例5: アイキャッチ画像のリンクを無効化

アイキャッチ画像のリンクを無効にして表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'isLink' => false ) ) );

例6: アイキャッチ画像のアスペクト比を設定

アイキャッチ画像のアスペクト比を設定して表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'aspectRatio' => '16:9' ) ) );

例7: アイキャッチ画像のスタイルをカスタマイズ

アイキャッチ画像にカスタムスタイルを適用して表示します。

echo render_block_core_post_featured_image( array( 'blockName' => 'core/post-featured-image', 'attrs' => array( 'style' => array( 'border' => array( 'radius' => '10px' ) ) ) ) );

注意点

  • この関数は、ブロックエディター内での使用を前提としています。テーマやプラグインで直接使用する場合は、適切なコンテキストを確認してください。
  • 引数の配列構造が正しくない場合、期待通りの結果が得られないことがあります。

関連機能: