在WordPress中的存档页面上需要帮助 [英] need help on archives pages in wordpress

查看:65
本文介绍了在WordPress中的存档页面上需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建自己的档案页面,以所需的格式显示.我想显示所有帖子标题,按月份和年份排序.它应该看起来像这样:

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.

这是我要构建 http://spyrestudios.com/archives/的存档页面示例.

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

请帮助. 提前致谢.

Please help. Thanks in advance.

推荐答案

您可以使用WP_Query来做到这一点

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

这篇关于在WordPress中的存档页面上需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆