wp query - Display WordPress Post By Date

admin2025-01-07  7

I want to show WordPress post by day/date in the homepage.

ex:

Monday, January 03

  • post 1
  • post 2
  • post 3

Sunday, January 02

  • post 1
  • post 2
  • post 3

Saturday, January 01

  • post 1
  • post 2
  • post 3

What WordPress query should I use?

Thanks. Sorry for bad English.

I want to show WordPress post by day/date in the homepage.

ex:

Monday, January 03

  • post 1
  • post 2
  • post 3

Sunday, January 02

  • post 1
  • post 2
  • post 3

Saturday, January 01

  • post 1
  • post 2
  • post 3

What WordPress query should I use?

Thanks. Sorry for bad English.

Share Improve this question edited Jun 17, 2024 at 10:54 bueltge 17.1k7 gold badges61 silver badges97 bronze badges asked Sep 16, 2015 at 8:46 Andrean SaputroAndrean Saputro 11 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

i think your question has been answered in here

$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(); // or whatever you want here.
echo '<br />';
endwhile; endif;
wp_reset_postdata();

More info on the query here: http://codex.wordpress.org/Class_Reference/WP_Query

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265413a1043.html

最新回复(0)