• Resolved wombat86

    (@wombat86)


    Hi. I am trying to make an archive page that displays all of the posts, grouped by date, like this:

    1/16/2013
    Post 1
    Post 2

    1/15/2013
    Post 3
    Post 4

    I ALMOST have it working using this code:

    $args = array('posts_per_page' => -1, 'orderby' => 'date' );
    $myQuery = new WP_Query($args);
    $date = '';
    
    if ( $myQuery->have_posts() ) : while ( $myQuery->have_posts() ) : $myQuery->the_post();
    
    if ( $date != get_the_date() ) {
        echo $date;
        echo '<hr />';
        $date = get_the_date();
    }
    
    the_title();
    echo '<br />';
    
    endwhile; endif;
    wp_reset_postdata();

    But the date is displayed below the post titles, as you can see here:
    https://cropcircleshawaii.com/test/all-posts/
    And I would like it displayed above the post titles. How do I do this?

    Thanks for your help!

Viewing 1 replies (of 1 total)
  • Thread Starter wombat86

    (@wombat86)

    I just figured this out,

    if ( $date != get_the_date() ) {
     $date = get_the_date();
     echo $date;

    I had to set the date variable before outputting it to make it show up before the post titles

Viewing 1 replies (of 1 total)
  • The topic ‘Archive page grouped by date’ is closed to new replies.