WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Archive page grouped by date (2 posts)

  1. wombat86
    Member
    Posted 1 year ago #

    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:
    http://cropcircleshawaii.com/test/all-posts/
    And I would like it displayed above the post titles. How do I do this?

    Thanks for your help!

  2. wombat86
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags