所以我一直在寻找这个答案,但没有找到答案——基本上我有一个包含在短代码中的WP查询。。我已经设置了paginate links函数,将其输出到页面上。但是,单击时页面url不会更改(href确实显示了正确的url--/page/2),我知道在短代码中执行时,这与主查询有关。任何帮助都将不胜感激。
$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
$args = array(
\'post_type\' => $type,
\'posts_per_page\' => -1,
\'orderby\' => \'rand\',
\'paged\' => $paged
);
$the_query = new WP_Query($args);
// Put default query object in a temp variable
$tmp_query = $wp_query;
// Now wipe it out completely
$wp_query = null;
// Re-populate the global with our custom query
$wp_query = $the_query;
?>
<div class="row">
<?php if ( $the_query->have_posts() ) : $i=0; ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$sphere = get_post_meta(get_the_id(),\'testimonial_profession\', true);
if ($i == 2) {
$i = 0;
?>
</div>
<div class="row">
<?php
}
?>
<div class="col-md-6 col-sm-12 col-xs-12">
<div class="testimonial_inner_wrapper">
<?php if(!has_post_thumbnail()): ?>
<h4 class="testimonials-inner-title"><?php the_title(); ?></h4>
<?php if(!empty($sphere)): ?>
<div class="testimonial_sphere"><?php echo($sphere); ?></div>
<?php endif; ?>
<div class="short_separator"></div>
<?php else: ?>
<div class="media">
<div class="media-left media-top">
<div class="testimonial-media-unit">
<?php the_post_thumbnail(\'img-69-69\', array(\'class\'=>\'testimonial-media-unit-rounded\')); ?>
</div>
</div>
<div class="media-body">
<h4 class="testimonials-inner-title"><?php the_title(); ?></h4>
<?php if(!empty($sphere)): ?>
<div class="testimonial_sphere"><?php echo($sphere); ?></div>
<?php endif; ?>
<div class="short_separator"></div>
</div>
</div>
<?php endif; ?>
<div class="testimonial_inner_content" style="color:#aaaaaa"><p><?php the_excerpt(); ?></p>
</div>
</div> <!-- inner wrapper -->
</div>
<?php $i++; endwhile; ?>
<!-- end of the loop -->
</div><div class="poNav">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $the_query->max_num_pages
) );
$wp_query = NULL;
$wp_query = $temp_query;
?></div>
<?php wp_reset_postdata(); ?>
<?php
$myvariable = ob_get_clean();
return $myvariable; ?>
<?php else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif;
}