Forums

Custom Date query (10 posts)

  1. keyframehq
    Member
    Posted 1 year ago #

    I am trying to create a Victorian-style blog where the date posts are shown as 1903 rather than 2011. I have been using the following custom date format: F, j, 1903

    However all this does is make every blog post exactly the same date regardless of when they are posted -i.e. today's date, 1903

    I would be very grateful for any help with this - my blog is at: http://www.drwatsonsblog.com

    Kind regards

    Neil

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Is this what you want? If a post date is February 10, 2010, you want to show February 10, 1903?

    If so, use this to display the date:

    date('F j, Y',strtotime('-107 years',strtotime($post->post_date)))

  3. keyframehq
    Member
    Posted 1 year ago #

    Thanks vtxyzzy, that's exactly what I'm trying to do. Where should I put this code specifically? Does it go in the custom format box of dashboard or need to be entered somewhere else within the code on one of the pages?

    Many thanks

    Neil

  4. vtxyzzy
    Member
    Posted 1 year ago #

    You need to replace the call to the_date() in your theme templates with this:

    echo date('F j, Y',strtotime('-107 years', strtotime($post->post_date)));

    Most of the time, the templates (index.php, single.php, etc) will have code like this:

    '<?php the_date(); ?>`

    Replace that with:

    <?php echo date('F j, Y',strtotime('-107 years', strtotime($post->post_date))); ?>
    `

  5. keyframehq
    Member
    Posted 1 year ago #

    Hmm both my index.php and single.php don't contain the date references at all and that syntax isn't showing in my theme template.

    The only reference to date I can find is in my functions.php which has the following:

    if (!function_exists('get_the_date')) {
    function get_the_date($format = 'F jS, Y') {
    return get_the_time(__($format, THEME_NS));

    Thanks again for your help on this.
    Neil

  6. vtxyzzy
    Member
    Posted 1 year ago #

    I see you are using an Artisteer theme, and you found the correct place to make the change. However, it is a bit different than I thought.

    Make a backup copy of functions.php first, because if you have an error in it, you will not be able to log in to your theme. You will have to use FTP to restore the copy.

    Try changing this:

    return get_the_time(__($format, THEME_NS));

    to this:

    global $post;
    return date(__($format, THEME_NS), strtotime('-107 years', strtotime($post->post_date)));
  7. keyframehq
    Member
    Posted 1 year ago #

    Thanks for the tip - I followed your instructions as you said but still not working. It still shows the date as 2010 and all the posts still have the same identical date on them even though they were added on separate days - strange.

    Thanks again for your help on this

  8. vtxyzzy
    Member
    Posted 1 year ago #

    Looks like you will need to change calls for get_the_time to get_my_time in your templates and rename the function in functions.php.

  9. keyframehq
    Member
    Posted 1 year ago #

    I've now renamed the function in functions.php
    Regarding the template I've used Artisteer to generate my blog. Should I be looking in page.php or somewhere else for the get_the_time reference?

    Thanks again for your help

  10. vtxyzzy
    Member
    Posted 1 year ago #

    I think the only other place is just a little further down in functions.php.

Topic Closed

This topic has been closed to new replies.

About this Topic