liquid2g Posted February 15, 2011 Share Posted February 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/ Share on other sites More sharing options...
phppaper Posted February 15, 2011 Share Posted February 15, 2011 go to single.php and delete the year of date there and add a manual year of date like Y+10 Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174370 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 You can do exactly what your wanting INSIDE of wordpress. No programming required. Go to the post you want to set a date for, and go to edit mode. Over on the right hand side you'll see all of the publish options. The publish date is listed there as well. Edit that, and change the year to 10 years in the future. That will show the date you have entered all throughout the site for that blog posts. Rinse/Repeat for any new or old blog posts that you want to post into the system. Very simple, no programming experience required. Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174388 Share on other sites More sharing options...
liquid2g Posted February 15, 2011 Author Share Posted February 15, 2011 Thanks Phppaper, I tried doing as you said, changing teh date in single.php to <?php the_time(__('M j, Y+10')) ?> but it ends up displaying at 2011+10 instead of 2021. What am I doing wrong? businessman332211, thanks for the suggestion, but setting a post date 10 years into the future within wordpress simply schedules the post to appear in 10 years time, rather than having it appear now with the future date. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174408 Share on other sites More sharing options...
phppaper Posted February 15, 2011 Share Posted February 15, 2011 Well, it is a PHP forum here, you can start another question asking about how to convert year into int and add 10 and echo it out. I just never counter such a case so cannot help Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174450 Share on other sites More sharing options...
silkfire Posted February 15, 2011 Share Posted February 15, 2011 It's very easy with the string-to-time function: echo date('M j, Y', strtotime('+10 years')); Prints February 15, 2021 Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174464 Share on other sites More sharing options...
liquid2g Posted February 15, 2011 Author Share Posted February 15, 2011 Thanks silkfire.... this is getting close to what I need but echo date('M j, Y', strtotime('+10 years')); gives me today's date 10 years into the future, wheras I need it to be the article/post date 10 years into the future. I tried echo the_time('M j, Y', strtotime('+10 years')); but it doesn't add the 10 years when I do this... Any ideas that would get me over the finish line? thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174484 Share on other sites More sharing options...
salathe Posted February 15, 2011 Share Posted February 15, 2011 Another approach would be to ignore all of the helpful comments here and attach a filter (using Wordpress's add_filter() in a plugin) to the_time to do any manipulation of the date/time that you want to do (including, adding 10 years). Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174489 Share on other sites More sharing options...
silkfire Posted February 15, 2011 Share Posted February 15, 2011 Ye the_time() is a custom WP function, try like this if you don't want to hook the_time() with add_filter(): echo date('M j, Y', strtotime('+10 years', strtotime(the_time('Y-m-d H:i')))); Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174494 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 Hey, your right. Strange I didn't notice that. Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174548 Share on other sites More sharing options...
liquid2g Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks Salathe. Your alternate suggestion sounds good, but I'm brand new to php and am unsure how to attach a filter (using Wordpress's add_filter() in a plugin) to the_time... And, thanks again to Silkfire - I tried echo date('M j, Y', strtotime('+10 years', strtotime(the_time('Y-m-d H:i')))); as you suggested, but it displays on the frontend as: "2011-02-07 16:18JAN 1, 1980" It seems that it's close to working but it has transported us back into 1980 Is there anything you can think of that I might change to get it working? thanks again in advance Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174784 Share on other sites More sharing options...
QuickOldCar Posted February 16, 2011 Share Posted February 16, 2011 Wouldn't the easiest way be to hop in a DeLorean 10 years to the future, do all the dates as normal and just time warp back to this date? I just couldn't resist, being that you are doing a science fiction blog and all. Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174842 Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 $year = date("Y"); $ten_years = $year + 10; $future = mktime(0,0,0,$month,$day,$ten_years); $future_date = date("F j, Y", $future); You can fill in the $month, $day, and whatever else you want. Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1174849 Share on other sites More sharing options...
liquid2g Posted February 17, 2011 Author Share Posted February 17, 2011 QuickOldCar, I would love to jump in the DeLorean, but it's in at the shop getting fixed at the moment, so all of my future travel needs to be done via php =) Thanks lalnfl, I tried adding this to single.php: <?php $year = date("Y"); $ten_years = $year + 10; $future = mktime(0,0,0,$month,$day,$ten_years); $future_date = date("F j, Y", $future); echo $future_date; ?> but it just returned the error "WARNING: MKTIME() EXPECTS PARAMETER 4 TO BE LONG, " any thoughts? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1175565 Share on other sites More sharing options...
liquid2g Posted February 17, 2011 Author Share Posted February 17, 2011 Aha! Finally got there 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"; ? 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! Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1175575 Share on other sites More sharing options...
silkfire Posted February 17, 2011 Share Posted February 17, 2011 Thanks Salathe. Your alternate suggestion sounds good, but I'm brand new to php and am unsure how to attach a filter (using Wordpress's add_filter() in a plugin) to the_time... And, thanks again to Silkfire - I tried echo date('M j, Y', strtotime('+10 years', strtotime(the_time('Y-m-d H:i')))); as you suggested, but it displays on the frontend as: "2011-02-07 16:18JAN 1, 1980" It seems that it's close to working but it has transported us back into 1980 Is there anything you can think of that I might change to get it working? thanks again in advance Strange my function should return February 07, 2021. I don't have WordPress but I substituted the_time() with date() and it worked. Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1175582 Share on other sites More sharing options...
silkfire Posted February 17, 2011 Share Posted February 17, 2011 liquid changing the Archives could be a bit tricky you need to hook the get_archives function. Maybe this can help? http://www.misthaven.org.uk/blog/2009/01/11/filtering-archives/comment-page-1/#comment-2097 Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1175584 Share on other sites More sharing options...
salathe Posted February 17, 2011 Share Posted February 17, 2011 If you hooked a little plugin into your Wordpress which alters what the_time() outputs, you would not have to change any of your theme files. I know that you said you're new to that, but it would be way easier than what it looks like you're currently trying to do! Quote Link to comment https://forums.phpfreaks.com/topic/227696-how-can-i-set-php-dates-10-years-into-the-future/#findComment-1175591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.