WordPress.org

Ready to get started?Download WordPress

Forums

the_date : working once per post ? (9 posts)

  1. Ozh
    Member
    Posted 10 years ago #

    Hi there
    When I try to use the_date() more than once in a post, only the first one displays something. Others just dont display anything
    Is there anything I misunderstood ? :)

  2. Mark (podz)
    Support Maven
    Posted 10 years ago #

    In index.php, you will see the date just outside of the 'post loop'
    If you want everything dated, you need to put that function call just inside the loop. I've not done it, but it's easy enough to do by trial and error I guess...

  3. Ozh
    Member
    Posted 10 years ago #

    Actually no, I'm talking about the_date() inside "the loop" :)
    Like, I'd like each post to display twice the date.

  4. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    Then use the_time() instead of the_date(). That's in the readme.

  5. Ozh
    Member
    Posted 10 years ago #

    Well. I am using the_time() of course. To display the time. Not the date.
    What I'm trying to get is, for each post :
    Sunday 12th March 2004
    This is the title
    posted by Joe, 03/12/04 @ 12:55
    This needs, if I'm correct, twice the_date() and once the_time() per post. What I actually get is :
    Sunday 12th March 2004
    This is the title
    posted by Joe, @ 12:55
    What I dont get is why would a template tag work once per post ? Sorry if I wasn't clear from the start

  6. Mark (podz)
    Support Maven
    Posted 10 years ago #

    There is a loop.
    In that loop, all tags are excuted for as many times as the loop is executed.
    If a tag is outside of that loop, it will be executed just the once.
    Try this:
    Put this
    <?php the_date; ?>
    Just before the
    '<?php the_time() ?>`
    in the div class="meta" line of the index.php.
    That will give you a date and time for each post actually in each post.

  7. Ozh
    Member
    Posted 10 years ago #

    Well, I think I understood the loop thingie. It *is* inside the loop.
    My code is :
    <? if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <? the_weekday_date('<h2><span>',' ') ; the_date('j F Y','','</span></h2>') ; ?>
    <div class="post">
    <h3 class="storytitle" id="post-<? the_ID(); ?>">" rel="bookmark" title="Permanent link : <? the_title_rss() ?>"><? the_title(); ?></h3>
    <div class="meta"> In: <? the_category(", ") ?> — <? the_author() ?> @ <? the_date('j F Y','','') ?> . <? the_time('H:m') ?> <? edit_post_link("x"); ?>
    </div>
    <div class="storycontent">
    <? the_content(); ?>
    (...)

    This gives :
    <h2><span>Tuesday 20 April 2004</span></h2>
    <div class="post">
    <h3 class="storytitle" id="post-6">This is a post</h3>
    <div class="meta">In: General — ozh @ . 13:04 x</div> <!-- meta -->
    <div class="storycontent"> [... the post itself ]

    The second "the_date" just doesnt show, and the first one, along with the_weekday_date(), display correctly.
    Thanks if anyone can help

  8. Skybly
    Member
    Posted 10 years ago #

    It's not a bug, it's a feature ;) the_date only "works" once for each day. If you want to display a date with every post, you need to use the the_time function and give it a formatting string as a parameter. See the documentation: http://wordpress.org/docs/template/#date_time

  9. Ozh
    Member
    Posted 10 years ago #

    Hooooooo. Ok :)
    I've been relying too much on the Wiki, where this "feature" isnt mentionned, and not enough on the Docs section itself.
    Many thanks to all :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.