2009-07-13 61 views
0

我是新来的WordPress。 我有我的网站(CMS)分为几个页面树状分层结构。 我试图查看子页面内特定类别的帖子。 但由于某些原因事件的简单的“循环”:howto使用WordPress的子页面来查看帖子?

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

仅显示(!!)的页面内容,并没有帖子在所有... 我怎样才能做到这一点?

10x。

回答

2

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

例子:

query_posts('showposts=5'); 

你可以看到完整的文档在这里:

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

我不是很确定你想要的,而循环内您的网页内容的方法调用,因为它会一遍又一遍显示。我建议将它移到循环之外。

顺便说一句,从一个特定的类别获得职位,使用方法:

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

当分类名是类本身的名称。这可能是该类别的slug名称,但我会先尝试。

0

您可以在循环内使用此命令在一个类别中生成最新帖子的(或列表)固定链接。将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