【发布时间】:2009-10-01 17:00:01
【问题描述】:
我正在尝试建立一个 single.php 页面。此页面用于显示完整的单个帖子。
我有 3 个循环。前两个用于(每个)从特定类别中获取随机帖子。
1
<?php query_posts(array('orderby' => 'rand', 'category_name' => announcement, 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
2
<?php query_posts(array('orderby' => 'rand', 'category_name' => quote, 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
问题在于应该显示真实帖子本身的第三个循环。
3
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<?php endif; ?>
^^ 这显示与 #2 相同的帖子。
所以,#1 和 #2 工作得很好,但是如何让 #3 显示它应该显示的单个帖子 - 例如,来自链接 http://example.com/one-post/ 标题为 one-post 的帖子应该被显示。
#1 和#2 位于页面的“顶部”区域,而#3 应位于页面中间。
【问题讨论】: