I’m trying to use a different WP_Query object depending on what type of page is being viewed. I’d like to do it without having to repeat the loop over and over again. I just want to use different WP_Query statements with a conditional. Is this possible, or is there another way to do this? Right now I’m only getting empty output on my pages. Code is below.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// retrieve posts based on category or pages
$args=array(
'category_name'=>'name',
'posts_per_page'=>10,
'paged'=>$paged
);
if (is_page()) {
//create a new instance
$wp_query = new WP_Query($args);
}
else {
//create a new instance
$wp_query = new WP_Query();
}
// the Loop
while ($wp_query->have_posts()) : $wp_query->the_post();
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// Do post layout here
endwhile;
$wp_query
is a global variable. Avoid use it for those things.