need help on archives pages in wordpress

2019-06-28 00:38发布

I want to build my own archives page that displays in the format that I want. I want to show all post title, 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 needs to be created for getting the post title and it's comments order by month.

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

Please help. Thanks in advance.

2条回答
疯言疯语
2楼-- · 2019-06-28 00:45

You can use WP_Query to do that

Try this code(i don't 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>';
    }
}
?>
查看更多
登录 后发表回答