代码之家  ›  专栏  ›  技术社区  ›  aviv

如何使用wordpress子页面查看帖子?

  •  0
  • aviv  · 技术社区  · 16 年前

    我是WordPress的新手。 我将我的网站(CMS)划分为树形层次结构中的几个页面。 但出于某种原因,事件出现了简单的“循环”:

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

    10倍。

    2 回复  |  直到 16 年前
        1
  •  2
  •   AlbertoPL    16 年前

    例子:

    query_posts('showposts=5');
    

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

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

    我不完全确定您是否希望在while循环中调用页面内容方法,因为它会反复显示。我建议把它移到循环之外。

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

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

        2
  •  0
  •   markratledge    16 年前

    <?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