Need help on wordpress archive pages

I want to create my own archives page that displays in the format that I want. I want to show all the headers, order by month and year. It should look like this:

  December 2011
 Post title 1
 3 comments

 Post title 2
 4 comments
  November 2011
 Post title 1
 2 comments

I’m having trouble figuring out the specifics of the loop that you need to create to get the message header, and it organizes by month.

This is an example archives page that I want to build http://spyrestudios.com/archives/ .

Please, help. Thank you in advance.

+4
source share
2 answers

You can use WP_Query for this.

Try this code (I have not tested it):

<?php $date = ''; $query = 'posts_per_page=9999'; $queryObject = new WP_Query($query); // The Loop... if ($queryObject->have_posts()) { while ($queryObject->have_posts()) { $queryObject->the_post(); $my_date = the_date('F j', '', '', FALSE); if ($my_date!=$date){ echo '<h2>'.$my_date.'</h2>'; $date = $my_date; } echo '<h3>'; the_title(); echo '</h3>'; echo '<span>'; comments_popup_link('No Comments Ā»', '1 Comment Ā»', '% Comments Ā»'); echo '</span>'; } } ?> 
0
source

Source: https://habr.com/ru/post/1386242/


All Articles