【问题标题】:Wordpress category page loop not displaying image and titleWordpress 类别页面循环不显示图像和标题
【发布时间】:2026-01-27 04:25:02
【问题描述】:

我是第一次来电的长期听众。

我正在开发一个 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(); ?>

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    变化:

    foreach($cat_posts as $post) : ?>
    

    收件人:

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

    【讨论】: