Wordpress,在循环中获取发布日期,而不是重复正确

Ben*_*ter 1 wordpress

我想得到发布日期和日期,我已经成功完成了这样的事情:

<?php $post_date = the_date('l,d', '', '', FALSE);
                    $post_date = explode(',', $post_date);?>

                    <div class="blogli">

                        <div class="cal">

                            <div class="day"><? echo $post_date[0] ?></div>

                            <div class="date"><? echo $post_date[1] ?></div>
Run Code Online (Sandbox Code Playgroud)

但问题是,当我将此代码放在循环中时,它不希望在echo语句中为我重复它.知道为什么吗?

这是完整的代码:

<ul>

                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                    <?php $post_date = the_date('l,d', '', '', FALSE);
                    $post_date = explode(',', $post_date);?>

                    <div class="blogli">

                        <div class="cal">

                            <div class="day"><? echo $post_date[0] ?></div>

                            <div class="date"><? echo $post_date[1] ?></div>

                        </div>

                        <li>

                        <h4><?php echo get_the_title(); ?></h4>

                        <?php the_excerpt(); ?>

                        </li>

                    </div>

                    <?php endwhile; else: ?>
                        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
                    <?php endif; ?>

                </ul>
Run Code Online (Sandbox Code Playgroud)

Dav*_*ner 5

当有多个帖子时你应该使用get_the_date.只需将您的代码更改为:

$post_date = get_the_date('l,d');

或者,该手抄本还建议您使用the_time:

$post_date = the_time('l,d');