Hi everyone, I'm writing a science fiction wordpress blog set 10 years into the future. I basically need all posts to display as if they are 10 years from now. Eg. posts needs to display as: February 7, 2021 instead of February 7, 2011 This will be for every post that I write. How can I automatically add 10 years to every post date? (And where would I put that code?) Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>` I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =) I hope someone out there can help. It would be very much appreciated. many thanks in advance Luke
$future_time = the_time(__('M j, ')) . (the_time(__('Y')) + 10); PHP: Not sure whether it works or not ( no access to a server at the moment ) but it should - let us know if you have any issues with implementing this.
Hi, the_time() function echoes the time out, so isnt suitable for what you want to do. You have 2 options; use a custom select and just add an interval of 10 years to the post_date, or perhaps easier you can use get_the_date inside the loop and it will give you the current posts date. Outsode of the loop, you will have to pass in the post id or post object. <?php $date = get_the_date(); $daymonth = date("M j", strtotime($date)); # the day and the month $year = date("Y", strtotime($date)) + 10; # the year print "$daymonth $year"; ?> PHP: This is suitable, as mentioned above, for sections of the site inside the loop. Should be fine to include this in theme files such as single.php etc
Use mktime() and simply add the expected time: $a = mktime() + 60 * 60 * 24 * 365 * 10 // Add 10 years Cheers.
Or you could read his question again and its how about how to get a wordpress date to the desired value? *sigh*
Thanks G3n3s!s, this looks good. I'm just not sure where to put the function you suggest in my wordpress files... any ideas to try would be very much appreciated.
Thanks lukeg32, this looks like it will work, but I'm not sure where this code should go. Sorry, I'm new to php -this is the first time I've needed to really get into it. =) I'd be very appreciative though if you could let me know.
okay, so sorry.. $date = get_the_date(); $futuretime = strtotime($date) + mktime(0,0,0,0,0,10); $date = date("d.m.Y", $futuretime);
Aha! Thanks Luke32! It works brilliantly with... <?php $date = get_the_date(); $daymonth = date("M j", strtotime($date)); # the day and the month $year = date("Y", strtotime($date)) + 10; # the year print "$daymonth $year"; ? PHP: I've implemented it across almost all dates on my wordpress site, but can't work out how to change the date in the 'Archives' widget sidebar. I tried archives.php but couldn't find what I needed to change... Does anyone know? thanks again!