私はwordpressを使用しています。最新のブログ投稿を表示するブログのランディングページを作成しようとしています。これまでのところ良いですが、イメージタグにブログ画像を表示するのが難しいです。私はget_the_id
機能を使ってpostIdを取得することができます。私もthe_date
機能を使って投稿の日付を知ることができました。wp_get_attachment_imageが動作していません。ブログ投稿の画像を表示するためにwordpress
しかし、私はwp_get_attachment_image
機能をブログ記事の画像を表示することができません。
以下のコードをご覧ください。
<?php $query = new WP_Query('posts_per_page=5'); ?>
<?php while ($query -> have_posts()) : $query -> the_post(); ?>
<div class="blog">
<img src="wp_get_attachment_image(get_the_ID()); ">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p><?php the_date(); ?></p>
<p><?php the_excerpt(__('(more…)')); ?></p>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
投稿IDと添付ファイルIDは同じですか。 https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ –
私はそう信じています。 –
もし私がこのデータをどのように入手できるかわからないのですか? –