I want to display a random page in the index page of my site and it's all good with that.The problem is that before the post I want to display a page depending in which category the post is posted.Website is about world countries so before the post I want to display a description of the country, some pictures and stuff.
The problem is that when I load a page, the post is no longer displayed(2pages are), so after loading a page I have to reset query.After that something bad happens and not 1 random post is displayed, but all the posts.
The code:
<?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; ?>
showposts
parameter, it's depreciated in favor ofposts_per_page
– mor7ifer Mar 5 '12 at 23:05