Forums

Resolving a Variable Issue Date (4 posts)

  1. steveniweiss
    Member
    Posted 1 year ago #

    I need every post on a site to be prefaced with the date as though it were published on Friday, even though it's not. It can be safely assumed that the post in question would never be published on any day other than Wednesday, Thursday, or Friday.

    Basically, whatever date the article is published, unless it's a Friday, the algorithm will look for the Friday that comes after the publishing date of a post, and store that in a variable that can be echoed.

    Let's say it starts with the following:
    $publishdate = the_date ('l, F j, Y', false);
    $publishday = explode (' ', $publishdate);
    if $publishday[0] = "Friday" : echo $publishdate;

    Here's where it gets a lot more messy, at least with straightforward code, especially when the month changes between Wednesday/Thursday and Friday. Is there a function in WordPress for just adding to a given date?

  2. Chip Bennett
    Member
    Posted 1 year ago #

    Might something like this work:

    $publish_day = the_date( 'l' );
    $days_to_add = '+0 days';
    if ( 'thursday' = $publish_day ) {
         $days_to_add = '+1 day';
    } elseif ( 'wednesday' = $publish_day ) {
         $days_to_add = '+2 days';
    }
    $actual_publish_date = the_date( get_option( 'date_format' ) );
    $displayed_publish_date = strtotime ( $days_to_add , strtotime ( $actual_publish_date ) ) ;

    Then, to output the "shifted" publish date:

    echo $displayed_publish_date;
  3. Chip Bennett
    Member
    Posted 1 year ago #

    Whoops!

    Replace:

    $publish_day = the_date( 'l' );

    With:

    $publish_day = get_the_date( 'l' );

    And replace:

    $actual_publish_date = the_date( get_option( 'date_format' ) );

    With:

    $actual_publish_date = get_the_date( get_option( 'date_format' ) );
  4. Chip Bennett
    Member
    Posted 1 year ago #

    I found another mistake. (Off my game today.)

    $publish_day = get_the_date( 'l' );
    $days_to_add = '0';
    if ( 'thursday' = $publish_day ) {
         $days_to_add = '1';
    } elseif ( 'wednesday' = $publish_day ) {
         $days_to_add = '2';
    }
    $date_shift = '+' . $days_to_add . ' day';
    $actual_publish_date = get_the_date( get_option( 'date_format' ) );
    $displayed_publish_date = strtotime ( $date_shift , strtotime ( $actual_publish_date ) ) ;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags