我想在我的网站的索引页面中显示一个随机页面,这一切都很好。问题是,在发布帖子之前,我想根据帖子发布的类别显示一个页面。这个网站是关于世界各国的,所以在发帖之前我想展示一个国家的描述,一些图片和东西。
问题是,当我加载页面时,将不再显示帖子(2页),因此加载页面后,我必须重置查询。之后,糟糕的事情发生了,显示的不是一篇随机帖子,而是所有帖子。
代码:
<?php global $more; $more = -1; //declare and set $more before The Loop ?>
<?php
query_posts(array(\'orderby\' => \'rand\', \'showposts\' => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<?php
if(in_category(\'afghanistan\')) {
$recent = new WP_Query("pagename=asia/afganistanas"); while($recent->have_posts()) : $recent->the_post();?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile;
}
elseif(in_category(\'albania\')) {
$recent = new WP_Query("pagename=europe/albania"); while($recent->have_posts()) : $recent->the_post();?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile;
}
else {
echo "Error!";
}
?>
<?php wp_reset_query(); ?>
<div id="loop">
<h1 class="post-title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile;
endif; ?>