在此片段中,Professional WordPress Design and Development, 2nd Edition的作者将 PHP 变量 ($wp_query)设置为 NULL 以将其完全刷新干净。
为什么在分配给它之前需要这样做?
<?php
$temp = $wp_query;
$wp_query= null;/***here***/
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$wp_query = new WP_Query( 'posts_per_page=5&paged='.$paged );/***here***/
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link( '« Previous' ); ?></div>
<div class="alignright"><?php next_posts_link( 'More »' ); ?></div>
</div>
<?php
$wp_query = null;/***here***/
$wp_query = $temp;/***here***/
?>