WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_date in multiple loops (7 posts)

  1. kingjeffrey
    Member
    Posted 8 years ago #

    I am using the_date function in multiple loops. However, the_date function does not expire after each loop. So, when the second loop begins with posts that are from the same date as the last posts from the previous loop (got that?), the_date does not appear. Any suggestions on how to have the_date behave in the second loop as if it had not been executed in the first? Thanks.

  2. moshu
    Member
    Posted 8 years ago #

    Read the Codex and use the_time.

  3. kingjeffrey
    Member
    Posted 8 years ago #

    moshu,

    Thank you for your help. I have read the codex, and the_time() does not suit my needs. I will explain with more detail, as clarification is warranted.

    Per the Codex:

    SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post [that is, the first instance of the_date()]. To repeat the date for posts published under the same day, you should use the Template Tag the_time() with a date-specific format string.

    This is precisely why I used the_date() in place of the_time(). I seek to use the_date() as a heading for multiple posts from the same day. the_time() repeats the day for each post. I only want it displayed once for each set of posts (from the same day).

    My problem is that I am using multiple loops, and the_date() does not expire after each loop. Suppose the first loop generates News items, and the second shows my blog entries.

    In the first (News) loop, suppose posts are displayed from 7/31/2006 - 8/1/2006. the_date() will display the date once above all posts from 8/1, then once above all posts for 7/31.

    Now in the second (Blog) loop, suppose posts exist from 7/30/2006 - 7/31/2006. the_date() will not place the date above the posts from 7/31, since that date was previously displayed in the first loop. It will, however, display the date once above posts from 7/30.

    Perhaps it would be beneficial to rephrase my question... How can I cause the_time() to reset after the first loop, so in the second loop, it will display the date above all groupings of posts by day? The Codex does not address this and an answer is not given in the support forums.

    Thank you again.

  4. moshu
    Member
    Posted 8 years ago #

    Oops, I guess I misread the original question.
    Unfortunately I am not a coder... but I remember several examples in the Codex about using multiple Loops - keeping the original or initiating a new query object.
    You may want to take a second look at those:
    http://codex.wordpress.org/The_Loop#Multiple_Loops

  5. kingjeffrey
    Member
    Posted 8 years ago #

    the only thing that appeared to be applicable was possibly rewinding the posts, but I was unable to find success. Any other ideas?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #


    function reset_the_date()
    {
    global $previousday;
    $previousday = '';
    }
    reset_the_date();

  7. kingjeffrey
    Member
    Posted 8 years ago #

    Thanks Otto. Simple solution, works perfect.

Topic Closed

This topic has been closed to new replies.

About this Topic