ループ処理をしているけども画像が1つしか表示されない
-
こんにちは。
loop.phpで画像があれば表示 なければ非表示で記事本文のみという処理をさせたいのですが、
画像が一番古い記事にしか表示できません。
ソースはこちらです。
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
?><div class=”post”>
<p>
<?php
$imgset = array(
‘post_type’ => ‘attachment’,
‘post_mime_type’ => ‘image’,
‘post_parent’ => $post->ID,
‘numberposts’ => ‘1’
);
$images = get_children($imgset);
$image = array_shift($images);
?><?php if($image): ?>
<h2>“><?php the_title(); ?></h2>
<?php echo wp_get_attachment_image($image->ID, ‘thumbnail’); ?>
<p><?php echo mb_substr(strip_tags($post-> post_content), 0, 150); ?></p><?php else: ?>
<h2>“><?php the_title(); ?></h2><p><?php echo mb_substr(strip_tags($post-> post_content), 0, 55); ?></p>
<?php endif; ?>
</p></div>
<?php
endwhile;
endif;
?>どなたか、わかる方がいれば手助けしていただきたいのです。
厚かましい話ですが、もし時間があればよろしくお願いいたします。
トピック「ループ処理をしているけども画像が1つしか表示されない」には新たに返信することはできません。