【问题标题】:Display Wordpress Archives one category at a time?一次显示一个类别的 Wordpress 档案?
【发布时间】:2009-06-17 12:50:33
【问题描述】:

我几乎完成了使用 Wordpress 进行自定义 CMS 的卑微尝试。我唯一的困难是让一个页面只显示一个类别的档案(它是孩子)。有人有想法吗? 非常感谢! 雷吉斯

【问题讨论】:

    标签: wordpress categories archive


    【解决方案1】:

    您可以使用WP_Query 类创建自己的自定义存档页面。具体来说,类似:

    <?php $query = new WP_Query('category_name=code'); ?>  
    <?php while ($query->have_posts()) : $query->the_post(); ?>
    <!-- display the category here --> 
    <?php endwhile; ?>
    

    您可以查看默认主题的 archive.php 以了解在您熟悉的布局中显示特定类别还需要什么。

    【讨论】:

      【解决方案2】:

      这是我用来显示“mycategory”类别的标题和永久链接的列表;这可以进入主 Wordpress 循环:

      <?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><?php endwhile; ?>
      

      将“-1”更改为“1”以仅显示最近的一篇文章;到“10”以显示最后 10 个帖子等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-04
        • 2015-04-19
        相关资源
        最近更新 更多