【问题标题】:howto use wordpress sub pages to view posts?如何使用wordpress子页面查看帖子?
【发布时间】:2009-07-14 06:01:45
【问题描述】:

我是 WordPress 新手。 我将我的网站 (CMS) 划分为树形层次结构中的多个页面。 我正在尝试查看子页面中特定类别的帖子。 但由于某种原因,事件是简单的“循环”:

<?php
if (have_posts()) :
   while (have_posts()) :
      the_post();
      the_content();
   endwhile;
endif;
?>

仅显示 (!!) 页面内容,根本不显示任何帖子... 我该怎么做?

10 倍。

【问题讨论】:

    标签: wordpress content-management-system wordpress-theming


    【解决方案1】:

    在循环开始之前,您需要先调用 query_posts()。

    例子:

    query_posts('showposts=5');
    

    您可以在此处查看完整文档:

    http://codex.wordpress.org/Template_Tags/query_posts

    我不完全确定您是否希望在 while 循环内调用您的页面内容方法,因为它会一遍又一遍地显示。我建议将它移到循环之外。

    顺便说一句,要获取特定类别的帖子,请使用:

    <?php query_posts('category=category-name'); ?>
    

    其中 category-name 是类别本身的名称。它可能是类别的 slug 名称,但我会先尝试。

    【讨论】:

      【解决方案2】:

      您可以在循环中使用它来生成一个(或列表)您在一个类别中的最新帖子的永久链接。将 mycategoryname 更改为您自己的类别,将 showposts 更改为 -1 以显示全部,或另一个数字以显示该帖子数。

      <?php $my_query = new WP_Query('category_name=mycategoryname&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; ?>
      

      WP_QUERY的基本思想在Wordpress

      就像The Loop, with examples

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-09
        • 1970-01-01
        • 2013-05-26
        • 1970-01-01
        • 1970-01-01
        • 2013-02-23
        相关资源
        最近更新 更多