is_new_day()WP 0.71

Checking the difference between the current date and the previous one (in a loop). Conditional tag.

The differences are checked for the current and previous posts in the WordPress loop. For this, global variables are used: $currentday and $previousday.

If the current day is new, the function will return true and false in all other cases.

Used By: the_date()

No Hooks.

Returns

Int. 1 - if it is a new day, 0 - if it is not a new day.

Usage

<?php
if( is_new_day() ){
	echo 'New day';
}
?>

Examples

0

#1 One post per group of posts published on the same day

An example of how you can use is_new_day() to display the inscription only once (for the first post) for all posts published on the same day.

The code is used inside the WordPress Loop:

if( is_new_day() ){
	echo "This post was not published on the same day as the previous one";
}

Notes

  • Global. String. $currentday The day of the current post in the loop.
  • Global. String. $previousday The day of the previous post in the loop.

Changelog

Since 0.71 Introduced.

is_new_day() code WP 7.0

function is_new_day() {
	global $currentday, $previousday;

	if ( $currentday !== $previousday ) {
		return 1;
	} else {
		return 0;
	}
}