I have made a custom loop in WordPress and for some reason, the date is being skipped on random intervals, even though the other post content is getting pulled in successfully every time.
Any ideas, because it is completely baffling me!
For example, a list of posts and when the date is missing:
- Date
- Date
- No date
- Date
- Date
- No date
- Date
- No date
- No date
- No date
Here is the code, including all the loops:
<?php query_posts('category_name=News&posts_per_page=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<article>
<div>
<p>PUBLISHED: <?php the_date(); ?></p>
<h4><a class="news_title_link" href="<?php the_permalink();?>"><?php the_title();?></a></h4>
<?php the_excerpt(); ?>
<br />
<a href="<?php the_permalink();?>">Read more</a>
</div>
<div>
<?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array('default_size' => 'thumbnail','default_image' => '/wp-content/uploads/2010/06/default-thumb.jpg'));} ?>
</div>
</article>
<?php endwhile; ?>
<?php endif;?>
One likely cause could be that the consecutive posts with no dates are all published on the same day as the one with a date that they all immediately follow.
In your example, the second and third posts may have the same publish date, which is causing the third post to not display a date. Likewise, posts 7 to 10 may share the same publish date, which is causing the last three posts to not display dates.
That, as far as I’ve experienced, is how
the_date()works. It prints a unique date only once throughout a loop.I work around it by either:
the_time()instead ofthe_date()and specifying a full date format, orunset($previousday)just after mythe_post()call