Support » Fixing WordPress » If The Post has been published within a week

  • Resolved Tom Morton

    (@tm3909)


    I thought I was becoming a guru of wordpress, but I was stumped today.

    I would like an if statement that checks if the post has been published for more than a week. If it hasn’t, I’ll display a “New” sticker. If it has, then the sticker goes away.

    Seems simple enough, but after an hour of searching and attempting, I figured I would just ask.

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    <?php
    $mylimit=7 * 86400; //days * seconds per day
    //$post_age = date('U') - get_post_time('U');
    $post_age = date('U') - mysql2date('U', $post->post_date_gmt);
    if ($post_age < $mylimit) {
    echo 'this post is within my date limit ';
    }
    ?>
    Thread Starter Tom Morton

    (@tm3909)

    I bow to the master bow

    Question though: Why multiply by the seconds per day?

    As I typed that, I realized why. The MySQL speaks in seconds, so how many seconds in a week? Well you’d multiply the number of seconds in a day times the number of days. So if the post is a week old, it echos.

    Never mind, question answered. Still bowing. Any advice for a kid trying to break out from the pack around here?

    MichaelH

    (@michaelh)

    Any advice for a kid trying to break out from the pack around here?

    Buy low and sell high!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If The Post has been published within a week’ is closed to new replies.