xiaolai
Forum Replies Created
-
Forum: Plugins
In reply to: Next page navigation doesn’t workI’ve fixed this, here’s the notes I’ve post on myblog(http://www.lixiaolai.com):
This is not because of your .htaccess configuration, but becausae of the mechanism of the query_post() function used by WordPress. When you’re using “index.php” as your “homepage”, the default query is used, but if you’re using “home.php” as your homepage (or you’re using a page template elsewhere), you’re in fact expected to use a customized query.In any page template, including user-defined “home.php”, you’d better define your own query, don’t simply write:
<?php query_posts(); ?> <?php query_posts( 'posts_per_page=25' ); ?>rahter, you should construct a new instance of $wp_query:
<?php $myqueryname = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=5'.'&paged='.$paged); ?>…, and then you can start the loop:
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> ... do whatever you like <?php endwhile; ?> <?php else : ?> ... what if there's no post matching myquery? <?php endif; ?>… and now your navigation links should work properly:
<div class="navigation"> <div class="alignleft"><?php previous_posts_link('« Previous') ?></div> <div class="alignright"><?php next_posts_link('More »') ?></div> </div>… and, you’d better not to forget destruct your instance of $wp_query:
<?php $wp_query = null; $wp_query = $myqueryname;?>Here’s the complete code of a page template that has working navigation links:
<?php /* Template Name: //Define Your Template Name Here */ ?> <?php get_header(); ?> <?php $myqueryname = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=25'.'&paged='.$paged); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> ... <?php endwhile; ?> <?php else : ?> ... <?php endif; ?> <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; $wp_query = $myqueryname;?> <?php get_sidebar(); ?> <?php get_footer(); ?>