WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] the_date not displaying correctly

[Resolved] the_date not displaying correctly

  • artikel104
    Member

    @artikel104

    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael
    Forum Moderator

    @alchymyth

    artikel104
    Member

    @artikel104

    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.

    Michael
    Forum Moderator

    @alchymyth

    I tried setting the $echo to true

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

    artikel104
    Member

    @artikel104

    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.

    Michael
    Forum Moderator

    @alchymyth

    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 );
    artikel104
    Member

    @artikel104

    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! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] the_date not displaying correctly’ is closed to new replies.