WordPress.org

Ready to get started?Download WordPress

Forums

Displaying formatted timestamp at the home page top in another language (9 posts)

  1. Slowfinger
    Member
    Posted 7 years ago #

    Hi,

    I'd like to have my home page display a formatted timestamp with just the current date before the latest entry of the day.

    I've been directed here, but I'm not sure I can handle that to say the least (no PHP savvy here).

    Of course a localised timestamp would best fit my site.
    Any hint or newbie-targeted link? Many thanks.

  2. maerk
    Member
    Posted 7 years ago #

    To insert the current date, you can use:

    <?php echo date('Y-m-d'); ?>

    This would give "2006-08-21".

    "21st August 2006" can be produced using:

    <?php echo date('jS F Y'); ?>

    To change the format of the date, change the letters you use. The letters, and what they represent, can be found on http://php.net/date

  3. Slowfinger
    Member
    Posted 7 years ago #

    Thanks a lot.

  4. Slowfinger
    Member
    Posted 7 years ago #

    Actually, what I was after was a way to gather the latest posts under the related timestamp, not the current one.

    So that, if the latest entries had been written yesterday, it would display the right date of yesterday rather than today at the top, and if posts from different days were included in the index/home page, all timestamps would consequently fit day by day.

    Too complicated a goal to achieve? Thanks in advance for any info or clarifications.

  5. Slowfinger
    Member
    Posted 7 years ago #

    Any idea?

  6. j459g
    Member
    Posted 7 years ago #

    So that, if the latest entries had been written yesterday, it would display the right date of yesterday rather than today at the top, and if posts from different days were included in the index/home page, all timestamps would consequently fit day by day.

    You can give any post any date and time you want by clicking "Edit" under that post, going to the "Post timestamp" facility near the bottom of the "Write Post" page, selecting "Edit timestamp" and then overwriting the current setting.

    If you happen to already have a post with the new date then you will add the re-dated post to that page.

    In your original query, you said:

    Of course a localised timestamp would best fit my site.

    Do you mean you would like to have the timestamp in a language that is different from that of the WordPress version you are using? Or do you mean you would like it to show a different time zone from the one it shows now?

    You can set any time zone you want in the Dashboard at "Options/Date and Time/Times in the weblog should differ by:" section.

    If you want a "timestamp" in a different language, as far as I can see the only easy way is to type it in by hand at the beginning of the text or put it in the "Title" line when you make the entry or manually edit in a date some time later.

  7. Slowfinger
    Member
    Posted 7 years ago #

    Thanks for your reply.

    I believe what I'm basically aiming at is:

    - moving the date from within each single post to above each latest post of the day, so the date will display only once on each single day, except of course when I'm not posting (I guess I'll then have to edit my stylesheet to make the whole think look somewhat decent)

    - getting the newly arranged datestamp formatted in another language (Italian, while I'm using the standard, non-Italian-localised K2 theme)

    (- Also with reference to K2 (I've also filed a query over at the K2 forum about this), I think having the time of posting shown, instead of the date, next to the watch icon, would be just great).

    I guess the whole thing implies editing the loop? Thanks for any directions.

  8. j459g
    Member
    Posted 7 years ago #

    I believe what I'm basically aiming at is: - moving the date from within each single post to above each latest post of the day, so the date will display only once on each single day, ...

    Well now, that is exactly what I have but I don't see why I get the date once only because I have the date inside the loop along with everything else related to the posts. As far as I can see, I ought to get the date before each post on the page.

    My index.php looks like this:

    <?php get_header(); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <div class="post">

    <?php /* ---- Date line (once per page only) --- */; ?>
    <?php $my_date = the_date('', '<h1 class="storydate">', '</h1>', FALSE); echo $my_date; ?>

    <?php /* ------- Titel line ---------- */; ?>
    <h2 id="post-<?php the_ID(); ?>" class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); ?><?php the_title(); ?>"><?php the_title(); ?></a></h2>

    <?php /* ------- Time line -------- */; ?>
    <p class="meta"><?php _e('Posted in'); ?> <?php the_category(', ') ?> <?php _e('at'); ?> <?php the_time(); ?> <?php _e('by'); ?> <?php the_author(); ?>

    <?php /* ------ Excerpt and content of post --- */; ?>
    <?php if (is_search()) { ?>
    <?php the_excerpt() ?>
    <?php } else { ?>
    <?php the_content(__('Read the rest of this entry »')); ?>
    <?php } ?>

    <?php /* ------- The feedback line ------- */; ?>
    <p class="feedback">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); ?> <?php the_title(); ?>" class="permalink"><?php _e('Permalink'); ?></a>
    <?php comments_popup_link(__('Comments'), __('1 Comment'), __('% Comments'), 'commentslink', __('Comments off')); ?>
    <?php edit_post_link(__('Edit'), ' · ', ''); ?>

    </div>
    <?php endwhile; ?>

    <?php else : ?>
    <h2><?php _e('Not Found'); ?></h2>
    <?php _e('Sorry, but no posts matched your criteria.'); ?>

    <?php include (TEMPLATEPATH . "/searchform.php"); ?>

    <?php endif; ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I have my date format in Options set to "l, jS F, Y" and I get a big "Wednesday, 23rd August, 2006" just once immediately under the header and nowhere else.

    There must be something in the date line (in "$my_date" or in "the_date"?) which prevents the appearance of the date twice on the same page but I have no idea how that works.

    On your second point (converting the date to Italian format), I need that, too, but have not got around to it yet. I would have to convert the day and the month and drop the "rd" and the commas.

    I assume that there is a php-routine available somewhere that could operate on the $my_date string to covert it to a different format before the "echo" but my php is not up to that at the moment!

  9. j459g
    Member
    Posted 7 years ago #

    I now see that the way to get one date per page is just as I thought - "the_date" is designed to appear only once on each page, see "SPECIAL NOTE" in:

    http://codex.wordpress.org/Template_Tags/the_date

    To get the result that you appear to be looking for, you would have to use a date line like the one on the example in my previous post instead of the date line you have at present which is clearly designed to appear above every post on the page.

Topic Closed

This topic has been closed to new replies.

About this Topic