I want to get the post date and day, which I have successfully done like so:
<?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>
yet the problem is, when I place this code within the loop, it doesn’t want to repeat it for me in the echo statements. Any idea why?
Here is the full code:
<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>
You should be using get_the_date when there are multiple posts. Just change your code to this:
$post_date = get_the_date('l,d');
Alternately, the codex also suggests that you use the_time:
$post_date = the_time('l,d');