【问题标题】:Display archive posts in Wordpress在 Wordpress 中显示存档帖子
【发布时间】:2010-06-07 08:00:34
【问题描述】:

我希望将档案页面显示为普通的帖子页面...

因此,带有二级导航的帖子页面显示:

最新帖子/上个月/去年/旧

在每个页面上,我想显示每个帖子的摘要,就像标准的最新新闻页面一样。当您单击时,您会看到完整的帖子。

对于每个菜单项,我创建了单独的页面模板,例如archives_month.php,然后在模板中而不是使用<?php wp_get_archives 我一直在使用<?php query_posts 并添加了一些时间参数,但不幸的是我没有找到最好的/正确的方法来获得这些呢。

我有一个有效的脚本:

<?php if (have_posts()) : ?>
<?php $current_month = date('m');?>
<?php $current_year = date('Y');?>
<?php $current_year = $current_year - 24;?>
<?php query_posts("cat=5&year=$current_year&monthnum=$current_month");?>

对于上个月的页面。但我现在不能将它用于 LAST YEAR 和 OLDER 帖子。

谁能帮帮我?我已经研究了许多不同的方法来做到这一点,但在一些博客上并不清楚,大多数人只是检索档案列表而不是显示帖子。

提前致谢。 梅尔

【问题讨论】:

    标签: php wordpress archive


    【解决方案1】:

    您应该能够使用query_posts() 将某些内容放在一起,如here 所述。

    来自链接页面的示例,用于构建查询以获取 2009 年 3 月的所有帖子:

    <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts for March 1 to March 15, 2009
        $where .= " AND post_date >= '2009-03-01' AND post_date < '2009-03-16'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>
    

    你会发现它很容易调整。

    然后可以使用循环来完成输出:

    // the Loop
    while (have_posts()) : the_post(); 
      // the content of the post
      the_content('Read the full post »'); 
    endwhile;
    

    有关如何自定义 The Loop 中显示的内容(以显示您谈论的摘要)的更多信息,请参阅here

    【讨论】:

    • 您好,感谢您的回复,但我看到了这一点并尝试实施它。我不确定这应该如何实现,因为我对 php 不太熟悉。我将所有这些代码放在我的archive_year.php 文件和循环中。你能告诉我一个例子,我需要把上面来自 Austin Matzko 的代码 sn-p 放在哪里吗?提前致谢!!梅尔
    • @missmonkee 我现在对 WP 模板的了解还不够深入,无法制作一个完整的示例,但您应该能够将第一个代码块放入任何使用循环的模板文件中 (while(have_posts()): .... ) 并且它应该将列表过滤到指定的时间段。
    • 不幸的是,这似乎不起作用,我不知道我做错了什么。这让我疯狂!看看这里: = '2010-05-01' AND post_date 你能看出这有什么问题吗?我检查了我的管理员,我确实有那个时期的帖子,但没有出现错误消息。帮助!
    猜你喜欢
    • 2017-09-06
    • 2021-04-06
    • 2019-06-27
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 2011-03-24
    • 1970-01-01
    相关资源
    最近更新 更多