I am adding post thumbnail jquery slider to header part but it’s resulting weird issue. It is somehow not ending while or stop query and so if I will go to single post or page it is keep displaying loop instead of page or post content.
I have tried two different query but none of them stopping to this weird issue.
First Tried
<?php
query_posts( 'post_status=publish&orderby=rand' );
while (have_posts()) : the_post();
$title_attr = array(
'title' => get_the_title(),
'alt' => get_the_title(),
'class' => get_the_title(),
);
echo '<a href="#post-'.get_the_ID().'" class="scroll theme">';
the_post_thumbnail('thumbnail',$title_attr);
echo '</a>';
endwhile; ?>
Than Second Tried
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('post_status=publish&orderby=rand');
// The Loop
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
$title_attr = array(
'title' => get_the_title(),
'alt' => get_the_title(),
'class' => get_the_title(),
);
echo '<a href="#post-'.get_the_ID().'" class="scroll theme">';
the_post_thumbnail('thumbnail',$title_attr);
echo '</a>';
endwhile; endif; wp_reset_query();?>
None of these stopping to display loop ( all post like index page) in to single post or page.
I found the solution 🙂
I have added if (have_posts()) before while and end loop with wp_reset_query() and all good now. 🙂
So here is final code if anyone having same problem..