首页 > 解决方案 > Wordpress 循环显示所有用户帖子,但带有 post_date

问题描述

如何获取列表中帖子名旁边的帖子日期?我尝试了以下代码,该代码将显示用户帖子的所有帖子名称,但只有第一个有日期,我猜这是今天的日期,而不是帖子本身的日期。

 <!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_date(); ?></a></li>
<?php endwhile; ?>
<!-- end of the loop -->

而此代码发布帖子的名称和每个帖子的内容。日期是错误吗?

<ul>

    <!-- the loop -->
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_content(); ?></a></li>
    <?php endwhile; ?>
    <!-- end of the loop -->

</ul>

标签: wordpresswhile-loopposts

解决方案


根据 Wordpress Codex 和 Wordpress Development Stack Exchange https://wordpress.stackexchange.com/a/125209上的其他帖子,该功能the_date()每天每页仅显示一次。解决方案是改用该功能。get_the_date()


推荐阅读