Jump to content

Recommended Posts

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

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.

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?

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!

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).

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

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.

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

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!

 

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.

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

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.