How to Display Date of Group Posts

Add Tool

How to Display Date of Group Posts


How to Display Date of Group Posts

In order to Display Date of Group Posts the date that a post was published, you have two options: <?php the_time(); ?> — displays the date for each and every post <?php the_date(); ?> — displays the date only once for each group of posts published on a certain day So, if you want to display list the post date next to each post, use the the_time() . On the other hand, you have multiple posts on any given day, use the_date() to list the post date only once for each day's posts. Something like this:

// the_time();

	Jan 01, 2013- Post #1
	Jan 01, 2013- Post #2
	Jan 01, 2013- Post #3

	Jan 02, 2013- Post #4
	Jan 02, 2013- Post #5
	Jan 02, 2013- Post #6

	Jan 03, 2013- Post #7
	Jan 03, 2013- Post #8
	Jan 03, 2013- Post #9

// the_date();

	Jan 01, 2013
		Post #1
		Post #2
		Post #3

	Jan 02, 2013
		Post #4
		Post #5
		Post #6

	Jan 03, 2013
		Post #7
		Post #8
		Post #9

Here I am going to create a loop using the_time() template tag and the_date() template tag.

Displays the date for each and every post

To display the date for each and every post I will use <?php the_time(); ?> in the loop. This snippets doesn’t need explaining, you will see result after using.

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

	<h1><?php the_title(); ?></h1>
	<p><?php the_time(); ?><p>
	<?php the_content(); ?>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

This loop will output the post title, date, and content for every post.

Displays the date only once for each group of posts

To displays the date only once for each group of posts published on a certain day I will use <?php the_date(); ?> in the loop. This snippets doesn’t need explaining, you will see result after using.

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

	<?php the_date('','<p>','</p><hr />'); ?>
	<h1><?php the_title(); ?></h1>
	<?php the_content(); ?>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

This loop will output the post title and content for every post, and also output the date for each group of posts published on any given day, as explained above. Notice we are adding the paragraph elements for the post date based on whether or not the date is actually output. If it is, then the date will be wrapped in <p> elements; if it’s not, no <p> elements will be output, thereby preventing repetitive sets of empty paragraph elements. Make sense? Good. Here are the available parameters for the nifty the_date() template tag:

<?php the_date('date format', 'before the date', 'after the date'); ?>

You can styled your Display Dates of Groups Posts by adding some CSS codes in you style.css file.

All credit goes: Devlounge


Tags: post date, wordpress post date, Display Date of Group Posts, post date only once, display list the post date
Payza

About Masum Billah

How to Display Date of Group Posts Hi I am Md. Masum Billah Contributor of this website. I always like to share various things with other. In this website I am sharing web design related tips and tricks, necessary web development tools, source codes for beginner and advance web developer.


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Display Date of Group Posts


adf.ly