• Hi, I’ve been searching a lot for this, but I can’t find it. I’ve tried to code it myself, but no luck.

    I would like to find a way of figuring out if a post is younger than 20 days. And than if it is younger I am going to post a small “NEW”-picture.

    I can do the picture thing myself with some if-else stuff, but the date part is tricky to me..

    How do I get the difference between CURRENT date and POST date, as a number in days, which then should be less than 20?

    Thanks in regards!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could use the php function strtotime()

    You can pass the function “-20 days” based on today. Then compare that with the timestamp from the post date in your IF statement.

    Thread Starter mowila

    (@mowila)

    Thank you so much ??

    $current_post_date = get_the_date();//get date string for current post
    	if ( strtotime($current_post_date) > strtotime('-20 days') ){
    		echo "NEW POST!!";
    	}
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘"NEW" badge on posts younger than 20 days’ is closed to new replies.