首页 文章

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

提问于
浏览
0

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

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

仅显示(!!)页面内容,根本没有帖子......我怎么能这样做?

10X .

2 回答

  • 0

    在循环开始之前,首先需要调用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

相关问题