Forums

Display different post template for week old posts (2 posts)

  1. reynoldsdigital
    Member
    Posted 4 months ago #

    Hi Guys,

    I'm looking to set up single.php so if the post has been published this week it goes to currentposts.php and if older than a week then archiveposts.php, these two display the posts differently.

    I can set it up so posts older than 7 days goes to archiveposts.php but I'm looking for post before Monday rather than 7 days ago.

    Many thanks, Barry Reynolds

  2. alchymyth
    The Sweeper
    Posted 4 months ago #

    this should get the date of the monday at the start of the current week:

    strtotime(date('Y')."-W".date('W')."-1")

    I don't remember how I got to this, however, there is lots of info on timestamps in:
    http://php.net/manual/en/function.strtotime.php
    http://php.net/manual/en/function.date.php

    hope this helps;

    (I used the snippet below to print the start and end date of the current week:
    `<?php echo 'this is week '.date('W').' - from '. date("d m Y", strtotime(date('Y')."-W".date('W')."-1")) .' to '.date("d m Y", strtotime(date('Y')."-W".date('W')."-7")) . "\n"; ?>

Reply

You must log in to post.

About this Topic

Tags