我正在抓取两组自定义元并循环浏览帖子,顺序是:自定义元1、帖子、自定义元2。但由于某种原因,如果我添加posts循环,第二组自定义meta将不会显示。
自定义元必须在循环中吗?如果没有循环调用,它似乎可以工作。
下面是我的代码:
<div class="col_1 maxheight">
<h1><a href="http://localhost/AMR/wp-content/uploads/2012/04/Title_Home.png"><img class="alignnone size-full wp-image-14" title="Title_Home" src="http://localhost/AMR/wp-content/uploads/2012/04/Title_Home.png" alt="" width="235" height="25" /></a></h1>
<p class="BodyHeader">
<?php if ( get_post_meta($post->ID, \'column1title\', true) ) : ?>
<?php echo get_post_meta($post->ID, \'column1title\', true) ?>
<?php endif; ?>
</p>
<?php if ( get_post_meta($post->ID, \'column1\', true) ) : ?>
<?php echo get_post_meta($post->ID, \'column1\', true) ?>
<?php endif; ?>
<br /><br />
<a href="http://localhost/AMR/wp-content/uploads/2012/04/eco-friendly_img.jpeg"><img class="alignnone size-full wp-image-11" title="eco-friendly_img" src="http://localhost/AMR/wp-content/uploads/2012/04/eco-friendly_img.jpeg" alt="" width="200" height="218" /></a>
</div>
<div class="separator maxheight"></div>
<div class="col_2 maxheight">
<h1></h1>
<p class="BodyHeader">Latest News</p>
<?php
$args = array( \'post_type\' => \'post\');
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<p class="BodySubHeader"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></p>
<p><?php the_content(); ?></p>
<?php
}
}
?>
</div>
<div class="separator maxheight"></div>
<div class="col_3 maxheight">
<h1></h1>
<p class="BodyHeader">
<?php if ( get_post_meta($post->ID, \'column3title\', true) ) : ?>
<?php echo get_post_meta($post->ID, \'column3title\', true) ?>
<?php endif; ?>
</p>
<?php if ( get_post_meta($post->ID, \'column3\', true) ) : ?>
<?php echo get_post_meta($post->ID, \'column3\', true) ?>
<?php endif; ?>
<br /><br />
<a href="http://localhost/AMR/wp-content/uploads/2012/04/MissionStatement_small_web.jpeg"><img class="alignnone size-full wp-image-15" title="MissionStatement_small_web" src="http://localhost/AMR/wp-content/uploads/2012/04/MissionStatement_small_web.jpeg" alt="" width="200" height="150" /></a>
</div>
它在一个页面上,所以我认为$post->ID是将ID设置为最后一篇文章,因此,不会拉取任何元,因为最后一篇文章没有元。但我不知道该怎么解决这个问题。