Forums

[resolved] date conditional (help!?) (5 posts)

  1. sodypop
    Member
    Posted 3 years ago #

    i am stumped. :-/
    i am trying to add a conditional for my posts stating basically the following:

    if this post was entered more than 2 weeks ago then do nothing.

    if it is newer than 2 weeks ago then echo "new".

    i for the life of me cannot figure it out.
    surely someone can help me with this one?
    i am sure it's basic php.

    here is the code that it will reside in:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="thumb">
    "><?php the_excerpt(); ?>
    <span class="thumbClient"><?php the_title(); ?></span>
    <div class="newPost">

    //new post conditional here

    </div>
    </div>
    <?php endwhile; endif; ?>

  2. Kafkaesqui
    Moderator
    Posted 3 years ago #

    http://wordpress.org/support/topic/67239#post-355805

    Change the "conditional" if statement to:

    if($days_since <= 14) :

  3. sodypop
    Member
    Posted 3 years ago #

    so what would the whole code chunk look like? (i'm not a programmer)

  4. Kafkaesqui
    Moderator
    Posted 3 years ago #

    It's at the end of the link. But... This would go where your "//new post conditional here" is:

    <?php
    $days_since = floor((date('U') - get_the_time('U')) / 86400);
    if($days_since <= 14) :
    ?>
    ~ This displays if post 14 days or newer ~
    <?php endif; ?>

  5. sodypop
    Member
    Posted 3 years ago #

    works like a charm! - THANK YOU!!

Topic Closed

This topic has been closed to new replies.

About this Topic