Wordpress类别页面循环不显示图像和标题

时间:2012-05-23 02:31:06

标签: php wordpress

我是长时间听众第一次来电。

我正在制作一个wordpress主题,我在我的类别页面上遇到了一个循环问题。我在类别页面上有2个循环,我遇到问题的第一个循环,假设显示用户正在查看的任何类别的最新帖子,而2循环显示其余帖子的网格。两个循环都工作,除了第一个没有拉标题或特色图像的帖子。这是代码 -

   <?php global $post; $cat_posts = get_posts('numberposts=1&category='.$catID);
foreach($cat_posts as $post) : ?>

<div class="featuredimagec"> <?php global $post; if(has_post_thumbnail()) {
the_post_thumbnail(); }?>
<p> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('large'); ?></a></p>   </div><div class="featuredcontenttex">
<?php $postTitle = get_the_title(); if($title != $postTitle) :?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?>
</a></h1><?php the_excerpt(); ?>
</div>

</div>
<?php endif ;?>
<?php endforeach; ?>
<?php wp_reset_query(); ?>

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:1)

变化:

foreach($cat_posts as $post) : ?>

要:

foreach($cat_posts as $post) : setup_postdata($post); ?>