WordPress.org

Forums

lost formatting when Replacing the_date() with the_time() (6 posts)

  1. tysonjs
    Member
    Posted 10 years ago #

    I just got wordpress this afternoon and I love it. I applied the Human Condition template but wanted to have the date on every post instead of once per day. Tried changing the template tag to the_time() in the index file and it works, i now have the date on every post, but it's not formatted as it was before.

    what I did was replace
    <?php the_date('','<h2>','</h2>'); ?>
    with
    <?php the_time('jS F Y','<h2>','</h2>'); ?>

    it seems like the_time() is not picking up the h2 style. is there a way to fix this? Thanks in advance!
    Tyson

  2. Kafkaesqui

    Posted 10 years ago #

    the_time() doesn't offer the same arguments as does the_date() (was never sure why), so you'll need to place its php tag within an <h2> element:

    <h2><?php the_time('jS F Y'); ?></h2>

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

  3. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    the_time() does not support before and after args. Just do this:

    <h2><?php the_time('jS F Y'); ?></h2>

  4. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    Hey, two answers that agree. How novel. ;-)

    the_date() supports before and after because it only creates output when the day changes. If you surrounded it with header tags, those tags would have nothing in between them for posts that aren't on a day boundary.

    the_time(), on the other hand, always creates output. You will never end up with empty tags.

  5. tysonjs
    Member
    Posted 10 years ago #

    awesome, thanks guys

  6. Kafkaesqui

    Posted 10 years ago #

    Was more like a short story, actually. But it had a satisfying end...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.