0

我尝试了在网络上找到的所有内容,但我遇到了错误,或者这不是我要搜索的内容......

我必须在wordpress中创建一个页面,只显示具有特定ID的类别的帖子(在我的情况下id = 8)我试图编辑loop-xxxx.php ..模板文件......除了我之外的一切总是遇到问题导航系统不起作用。我的意思是......回到旧帖子将不起作用,因为输出显示最后的帖子而不是旧帖子。

我在循环或模板文件中使用的代码是:

<?php
query_posts('cat=8');
while (have_posts()) : the_post();
the_content();
endwhile;
?>

我试着在

<?php while ( have_posts() ) : the_post(); ?>

在循环.php

或在 index.php 内的循环调用之前

请帮我 :\

4

2 回答 2

0

检查这个。

<?php query_posts($query_string . '&cat=8'); ?>

<?php if (have_posts()) : ?>
<optional> You can write here: "You are in category X". </optional>
<?php while (have_posts()) : the_post(); ?>

祝你好运。

于 2012-03-17T03:54:34.003 回答
0

One solution is to use a custom WP_Query. In the custom page's TEMPLATE file, where ID is the id of the targeted category:

<?php $tmp_query = new WP_Query('cat=ID');
    while ( $tmp_query->have_posts() ) : $tmp_query->the_post();
        the_content();
    endwhile;
    wp_reset_postdata();
?>
于 2012-01-16T20:03:27.820 回答