WordPress.org

Forums

[resolved] the_date not displaying correctly (7 posts)

  1. artikel104
    Member
    Posted 2 years ago #

    Hi All,

    I have the following code as part of The Loop:

    // show the date of the posts
                    $html .= the_date('l j F','<h2 style="margin-bottom:10px!important">','</h2><hr style="height:1px!important">');
    
                    // make post container and show post title
    		$html .= '
                        <div id="post-' .get_the_ID().'" style="margin-bottom:0px!important">
                            <p style="margin:0px">' .get_the_date('H:i'). ' | <a href="#">' .get_the_title(). '</a></p>
                            <div id="' .get_the_ID().'" class="post-content" style="display:none">';

    If the posts are of more then one day, the days will all show above the posts. I don't understand how this happens. I do need the_date function because the_time and get_the_date return the day as many times as there are posts on that day. However, if I change the_post to any of those, the text is displayed correctly. What am I doing wrong? Why do the days all appear on the top of my page (see http://www.artikel104.nl/wordpress/).

    Thanks

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

  3. artikel104
    Member
    Posted 2 years ago #

    I tried setting the $echo to true but this didn't change the output. The days keep appearing all under each other in stead of grouping the posts and putting the day above the group that is of that day...

    The get_the_date function always returns the date which I don't want. I want like this:

    Wednesday 7th July
    post 6
    post 5
    post 4

    Tuesday 6th July
    post 3
    post 2
    post 1

    In stead of what I get now:
    Wednesday 7th July
    Tuesday 6th July
    Post 6
    post 5
    post 4
    post 3
    post 2
    post 1

    Any clue on why the_date function doesn't work according to the first sample on my page? (while it does work on the 'classic' theme in WordPress.

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    I tried setting the $echo to true

    true is the default to echoe the date - try false to return the date

  5. artikel104
    Member
    Posted 2 years ago #

    Sorry, I mean false. Tried that too... If I put it to false, assign it to a variable (e.g. $trydatethisway) and then echo the variable, gives the same result.

  6. alchymyth
    Forum Moderator
    Posted 2 years ago #

    please post the full code of the template - in a pastebin http://codex.wordpress.org/Forum_Welcome#Posting_Code

    PS:

    just tested with a Twenty Twelve child theme, local xammp server - this really should work:

    $html .= the_date('l j F','<h2 style="margin-bottom:10px!important">','</h2><hr style="height:1px!important">', false );
  7. artikel104
    Member
    Posted 2 years ago #

    I got it fixed with the following code:

    $html .= the_date('l j F', '<h2 style="margin-bottom:10px!important">', '</h2>', false);

    I must have mistyped somewhere in my previous tries. Sorry for the confusion! Thanks for the support! :)

Topic Closed

This topic has been closed to new replies.

About this Topic