single.php
以下のPHPコードを使用して、メインの投稿ページの最後に関連する投稿を表示しようとしています。
例: ホームページ>投稿をクリック>投稿ページ(single.php)>コンテンツの下には、サムネイル付きの3つの関連する投稿があります。
これが私が試していることです:
<!-- Related Stories -->
<div class="postCategory" style="">Related Stories<br />
<div class="clear"></div>
<div style="width:100%;" align="center">
<div style="width:495px;" align="center">
<?php foreach( $Featuredposts as $post ) : setup_postdata($post); ?>
<?php //$do_not_duplicate[] = $post->ID; //print("$do_not_duplicate"); ?>
<?php if($featured_image=get_post_meta($post->ID, "featured_image", true)) { ?>
<div style="display:block; width:150px; margin:0 15px 0 0; float:left" align="center">
<a class="oborder" href="<?php the_permalink() ?>"><img src="<?php echo $featured_image; ?>" heigh="124" width="143" border="0" /></a>
<span style="display:inline;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" style="display:inline;"><?php the_title(); ?></a></span>
</div>
<?php }?>
<?php endforeach; ?>
<div class="clear"></div>
</div>
</div>
<!-- End Pull in Related Stories -->
これが私が得ているエラーです:
Warning: Invalid argument supplied for foreach() in /data/24/1/0/139/1815302/user/1967139/htdocs/RIF/wp-content/themes/crown_readitforward2012/single.php on line 280
280行目= <div style="width:495px;" align="center">
??
(それを削除すると、281行目でエラーが発生します)
281行目= <?php foreach( $Featuredposts as $post ) : setup_postdata($post); ?>