Forums

"NEW" badge on posts younger than 20 days (4 posts)

  1. mowila
    Member
    Posted 1 year ago #

    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!

  2. WPsites
    Member
    Posted 1 year ago #

    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.

  3. mowila
    Member
    Posted 1 year ago #

    Thank you so much :)

  4. WPsites
    Member
    Posted 1 year ago #

    $current_post_date = get_the_date();//get date string for current post
    	if ( strtotime($current_post_date) > strtotime('-20 days') ){
    		echo "NEW POST!!";
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic