简体   繁体   English

WordPress的多循环问题

[英]wordpress multiple loops problem

i am trying to build up a single.php page. 我正在尝试建立一个single.php页面。 this page is used to show a full single post. 此页面用于显示完整的单个帖子。

i have 3 loops on it. 我有3个循环。 first two are used (each) for geting a random post from a specific category. 前两个(每个)用于从特定类别获取随机帖子。

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

the problem is with the third loop that should display the REAL post itself. 问题是第三个循环应显示REAL帖子本身。

3 3

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

^^ this displays the same post as #2. ^^这与#2显示相同的帖子。

so, #1 and #2 work great, but how to get the #3 to display the single post that it is supposed to - for example from link http://example.com/one-post/ the post titled one-post should be displayed. 因此,#1和#2的效果很好,但是如何使#3展示应该显示的单个帖子-例如,从链接http://example.com/one-post/称为一帖的帖子中应该显示。

#1 and #2 are in the 'top' area of the page and #3 should be in the middle of the page. #1和#2位于页面的“顶部”区域,而#3应该位于页面的中间。

fixed. 固定。

fixed it. 修复。 changed #1 and #2 to 将#1和#2更改为

<?php
    $randomAnnouncement = new WP_Query();
    $randomAnnouncement->query('cat=545&showposts=1&orderby=rand');
    while ($randomAnnouncement->have_posts()) : $randomAnnouncement->the_post();
?>

<?php the_content(); ?>

<?php endwhile; ?>

and

<?php
    $randomQuote = new WP_Query();
    $randomQuote->query('cat=546&showposts=1&orderby=rand');
    while ($randomQuote->have_posts()) : $randomQuote->the_post(); ?>

<?php the_content(); ?>

<?php endwhile; ?>

and #3 remained as is. #3保持原样。

hope this helps someone else. 希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM