Convert Year to YC for EVE (OOC)

 

I cannot believe that this was as easy as it turned out to be. I had discussed this with Xeross a short while ago, but a tweet by Rettic reminded me about it this afternoon. I had wanted a way to show the year on my posts as the EVE year, and a simple little PHP script has done it for me.

So, the code:

<?php
$year = date('Y');
$month = date('m');
$day = date('d');
$year = $year - 1898;
$date = 'YC-' .$year. '-' .$month. '-' .$day;
echo $date
?>

The echo isn’t really needed here (for non PHP types echo just makes it print to screen), but wherever you want your date to show up replace it with that variable.

Now it is just a matter of editing the pages to put it in the proper place, which I haven’t gotten around to doing just yet, but will fairly soon.

Edit: Did a Theme Switch for proof of concept, as soon as I figure out how to get it to work with Mystique, I will switch it back. Damn Mystique…

Edit 2: As Rettic pointed out in the comments, Tumblr is a little bitch, but I have smacked that bitch into submission. JavaScript to do the same thing as the PHP above:

<script type=text/JavaScript>
var now = new Date();
now.getDate();
var year = now.getFullYear();
var year = year - 1898;
document.write("YC-" + year);
</script>

Just find the {Year} in your Tumblr theme and replace it with the script above.

Proof of concept: My Tumblr with its single post


Edit 3: It appears Rettic has dsicovered that all you need for Tumblr is:

<script type=text/javascript>
var year = {Year} - 1898;
document.write("YC-" + year);
</script>

To get it to work. Awesome job Rettic!

  • http://twitter.com/Rettic @Rettic

    Ah you rock Dingo.

    Unfortunately I think I'm finding that Tumblr isn't very forgiving for using php script in your theme file (html, css). I drop this in, but absolutely nothing shows. Not sure if I'm putting it in incorrectly, or I'm finding my first major limitation of Tumblr. Hm.

    • http://intensedebate.com/profiles/grimmlock grimmlock

      Didn't even think about you being on Tumblr, it will only work if you actually have the ability to edit your themes, so self hosted and maybe Blogger.I don't think Tumblr will even let you do it with Javascript. I have a Tumblr that I never use, so when I get a chance I'll mess around and see if I can find a way to get it to work.Krispy

      • http://twitter.com/Rettic @Rettic

        Worked! Awesome. Thanks for doing that. It'll do for now in that it'll change automatically next year, but the only think to figure out is how to associate the correct year for the time each post was made. Right now, even posts I did last year still show as YC-112, instead of YC-111. I think, to do that, we'd have to call in Tumblr code within the script. Is that even possible?

        • http://intensedebate.com/profiles/grimmlock grimmlock

          That is because it is pulling it in based off current year. Hmmm, I will ponder that and see what I can come up with.

  • http://twitter.com/Rettic @Rettic

    Ah you rock Dingo.

    Unfortunately I think I'm finding that Tumblr isn't very forgiving for using php script in your theme file (html, css). I drop this in, but absolutely nothing shows. Not sure if I'm putting it in incorrectly, or I'm finding my first major limitation of Tumblr. Hm.

    • http://intensedebate.com/profiles/grimmlock grimmlock

      Didn't even think about you being on Tumblr, it will only work if you actually have the ability to edit your themes, so self hosted and maybe Blogger.

      I don't think Tumblr will even let you do it with Javascript. I have a Tumblr that I never use, so when I get a chance I'll mess around and see if I can find a way to get it to work.

      Krispy

      • http://twitter.com/Rettic @Rettic

        Worked! Awesome. Thanks for doing that. It'll do for now in that it'll change automatically next year, but the only think to figure out is how to associate the correct year for the time each post was made. Right now, even posts I did last year still show as YC-112, instead of YC-111. I think, to do that, we'd have to call in Tumblr code within the script. Is that even possible?

        • http://intensedebate.com/profiles/grimmlock grimmlock

          That is because it is pulling it in based off current year. Hmmm, I will ponder that and see what I can come up with.

  • http://intensedebate.com/people/jorshan jorshan

    Krispy-

    Would it be possible to see a copy of your WordPress loop code? For some reason (don't know what it is), I'm not getting any results when I attempt to insert the above code into the loop in my "home.php" file

    Jorshan

    • Anonymous

      I actually did not put anything into home.php. The easiest way I found to modify the date was to change it where they showed the year in the main index template, single post, and comments.

  • http://intensedebate.com/people/jorshan jorshan

    Krispy-

    Would it be possible to see a copy of your WordPress loop code? For some reason (don't know what it is), I'm not getting any results when I attempt to insert the above code into the loop in my "home.php" file

    Jorshan

    • http://intensedebate.com/profiles/grimmlock grimmlock

      I actually did not put anything into home.php. The easiest way I found to modify the date was to change it where they showed the year in the main index template, single post, and comments.

  • http://twitter.com/jorshan @jorshan

    yeah, i tried that, inserting your code snippet in there (as well as the home.php – which is what autofocus uses to generate the main front page) but it keeps bombing out with a t-string error.

    i'll give it another go. i also have a guy in my office who's sharp with php and might have him take a peek.

    • Anonymous

      Sounds like autofocus usese some items that Mystique does. This is not the theme I usually use, I just wanted to get it working. Based off what Xeross said, I am going to revisit tonight and see if I can improve it, and make it work with the more complicated themes.

  • http://twitter.com/jorshan @jorshan

    yeah, i tried that, inserting your code snippet in there (as well as the home.php – which is what autofocus uses to generate the main front page) but it keeps bombing out with a t-string error.

    i'll give it another go. i also have a guy in my office who's sharp with php and might have him take a peek.

    • http://intensedebate.com/profiles/grimmlock grimmlock

      Sounds like autofocus usese some items that Mystique does. This is not the theme I usually use, I just wanted to get it working. Based off what Xeross said, I am going to revisit tonight and see if I can improve it, and make it work with the more complicated themes.

  • http://twitter.com/jorshan @jorshan

    Hmm. I'm using Autofocus as mentioned, and it's based off of the Sandbox WordPress theme. There might indeed be something in there hosing the works up somehow like the Mystique theme. If you want I can donate my source code to you to take a peek at what I'm doing in there. I'm going to keep plugging away at it, if I discover something interesting I'll send it along your way. Hopefully my co-worker will be able to point out something obvious i'm missing.

    • Anonymous

      I have Autofocus installed. I will take a look at it tonight after job number 2 and see what we can do to make it work and also make it better.

      Needs to be future proofed and past proofed, which it currently isn't.

  • http://twitter.com/jorshan @jorshan

    Hmm. I'm using Autofocus as mentioned, and it's based off of the Sandbox WordPress theme. There might indeed be something in there hosing the works up somehow like the Mystique theme. If you want I can donate my source code to you to take a peek at what I'm doing in there. I'm going to keep plugging away at it, if I discover something interesting I'll send it along your way. Hopefully my co-worker will be able to point out something obvious i'm missing.

    • http://intensedebate.com/profiles/grimmlock grimmlock

      I have Autofocus installed. I will take a look at it tonight after job number 2 and see what we can do to make it work and also make it better.

      Needs to be future proofed and past proofed, which it currently isn't.

  • http://twitter.com/jorshan @jorshan

    got it for wordpress: <?php $year = get_the_time('Y') – 1898; echo 'YC' .$year. ': ' .get_the_time('M'). '-' .get_the_time('d'); ?>

    • Anonymous

      Also, that will make it work forever, all posts from last year and into the future. Awesomesauce, mate!

  • http://twitter.com/jorshan @jorshan

    got it for wordpress: <?php $year = get_the_time('Y') – 1898; echo 'YC' .$year. ': ' .get_the_time('M'). '-' .get_the_time('d'); ?>

    • http://intensedebate.com/profiles/grimmlock grimmlock

      Also, that will make it work forever, all posts from last year and into the future. Awesomesauce, mate!

  • http://twitter.com/jorshan @jorshan

    try this for your single.php. i just D/L mystique and checked out the code. This may work.

    $year = get_the_time('Y') – 1898;
    printf(__('This entry was posted by %1$s on %2$s at %3$s, and is filed under %4$s. Follow any responses to this post through %5$s.', 'mystique'), ''. get_the_author() .'', 'YC' .$year. ': ' .get_the_time('M'). '-' .get_the_time('d'),get_the_time(get_option('time_format')), get_the_category_list(', '), '<a href="'.get_post_comments_feed_link($post->ID).'" title="RSS 2.0">RSS 2.0');echo ' ';

    • Anonymous

      meh, Mystique is being annoying. I actually don't like the theme that much, some of it appears a bit cartoony. Temporary switch to one of the basic WP themes, with years all changed nicely thanks to you, until I find something I like better.

  • http://twitter.com/jorshan @jorshan

    try this for your single.php. i just D/L mystique and checked out the code. This may work.

    $year = get_the_time('Y') – 1898;
    printf(__('This entry was posted by %1$s on %2$s at %3$s, and is filed under %4$s. Follow any responses to this post through %5$s.', 'mystique'), ''. get_the_author() .'', 'YC' .$year. ': ' .get_the_time('M'). '-' .get_the_time('d'),get_the_time(get_option('time_format')), get_the_category_list(', '), '<a href="'.get_post_comments_feed_link($post->ID).'" title="RSS 2.0">RSS 2.0');echo ' ';

    • http://intensedebate.com/profiles/grimmlock grimmlock

      meh, Mystique is being annoying. I actually don't like the theme that much, some of it appears a bit cartoony. Temporary switch to one of the basic WP themes, with years all changed nicely thanks to you, until I find something I like better.

  • http://twitter.com/jorshan @jorshan

    the only improvement i could see would be to make it a function, or possibly a plugin to make it easier to work with other WP themes and abstract the code from the theme itself to make it easier to upgrade theme later on. but for now, it works. enough for me to play more eve and less messing with "teh code"
    :)

  • http://twitter.com/jorshan @jorshan

    the only improvement i could see would be to make it a function, or possibly a plugin to make it easier to work with other WP themes and abstract the code from the theme itself to make it easier to upgrade theme later on. but for now, it works. enough for me to play more eve and less messing with "teh code"
    :)

  • http://www.starfleetcomms.com/ Max Torps

    What an inspiration! I tried to apply this to my Drupal site and have finally cracked it now!

    To complete you need to edit the node.tpl.pho file and replace the following line:

    With:
    created);
    $year=(int)$year;
    $month = date(‘m’, $node->created);
    $day = date(‘d’, $node->created);
    $ycyear = $year-1898;
    $date = “YC-” .$ycyear. “-” .$month. “-” .$day;
    print “Transmitted by “. $name . ” | ” . $date;
    ?>

  • http://www.starfleetcomms.com Max Torps

    What an inspiration! I tried to apply this to my Drupal site and have finally cracked it now!

    To complete you need to edit the node.tpl.pho file and replace the following line:

    With:
    created);
    $year=(int)$year;
    $month = date(‘m’, $node->created);
    $day = date(‘d’, $node->created);
    $ycyear = $year-1898;
    $date = “YC-” .$ycyear. “-” .$month. “-” .$day;
    print “Transmitted by “. $name . ” | ” . $date;
    ?>

  • Pingback: Wordpress Blogs with YC years, the Function! (OOC)