WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional Statements and Dates (4 posts)

  1. mahodder
    Member
    Posted 6 years ago #

    Hi,

    I am having issues coding a conditional statement, hoping someone here can help me out.

    I have the following in my template:

    Visits since <?php the_date('F d, Y', '', ''); ?>

    Now if the date of the post is before July 2008, I just want it to display, July 2008 for all cases instead of grabbing the posts date.

    If it's August 2008 or later I want it to show the date of the post like I have above.

    Playing with the If statement, but so far with out success.

    Thanks for any insights!

  2. mahodder
    Member
    Posted 6 years ago #

    Anyone?

    Is this question better suited for a different area of the forum?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    $julytime = mktime(0, 0, 0, 1, 7, 2008));
    if (get_the_time('U') < $julytime) echo "July 2008";
    else the_time('F d, Y', '', '');

    I use the_time because the_date won't display twice in a row if it's on the same date. See here: http://codex.wordpress.org/Template_Tags/the_date

  4. mahodder
    Member
    Posted 6 years ago #

    Thanks that's what was tripping me up!

    For anyone else I was able to get it working with a few minor adjustments:

    <?php $julytime = mktime(0, 0, 0, 7, 31, 2008);
    if (get_the_time('U') < $julytime) echo "July 2008";
    else the_time('F d, Y', '', '');
    ?>

    Took out the extra bracket in the mktime statement and modified the the date slightly.

Topic Closed

This topic has been closed to new replies.

About this Topic