need help on archives pages in wordpress

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 16:08:36

问题


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.


回答1:


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>';
    }
}
?>



回答2:


this may help you.

http://codex.wordpress.org/Creating_an_Archive_Index



来源:https://stackoverflow.com/questions/8500386/need-help-on-archives-pages-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!