需要有关 wordpress 档案页面的帮助 [英] need help on archives pages in wordpress

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

问题描述

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

<前>2011 年 12 月帖子标题 13 条评论帖子标题 24 条评论

<前>2011 年 11 月帖子标题 12 条评论

我无法弄清楚为获取帖子标题而需要创建的循环的细节,以及按月排列的评论顺序.

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

请帮忙.提前致谢.

解决方案

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

试试这个代码(我没有测试过):

have_posts()) {而 ($queryObject->have_posts()) {$queryObject->the_post();$my_date = the_date('F j', '', '', FALSE);如果($my_date!=$date){echo '<h2>'.$my_date.'</h2>';$date = $my_date;}回声'<h3>';标题();回声'</h3>';echo '';comments_popup_link('没有评论 »', '1 条评论 »', '% 评论 »');回声'</span>';}}?>

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.

解决方案

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天全站免登陆