first of all, i've been on google, stackexchange , codex still can't solve problem. might simple; not sure. have following function lists custom posts. page has more 1 query 1 (this one) make use of pagination. it's on front page - set static.
here function:
function wight_listings() { global $wp_query; global $page; $backup = $wp_query; $wp_query = null; $cur_page = $page; //get_query_var('page') ? get_query_var('page') : 1; $args = array( 'post_type' => array('wight_listing'), 'posts_per_page' => 7, 'paged'=>$cur_page ); $wp_query = new wp_query($args); ?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> . . . <?php endwhile; ?> <div id="nav-posts" style="margin-top: .5em;"> <div style="float:left;"><?php previous_posts_link('previous listings «'); ?></div> <div style="float:right;"><?php next_posts_link('» next listings'); ?></div> <div class="clear"></div> </div> <?php else: ?> <p>oh no! there's nothing show. :(</p> <?php endif; ?> <?php $wp_query = null; $wp_query = $backup; }
the 'next listings' links shows linking page 2 no matter page on , 'previous listings' link never show up.
what doing wrong?
wp: 3.5.2
i found solution. looked /wp-includes/link-template.php , found 2 functions responsible mysery. copied them theme , modified little , works fantastically.
function wight_get_previous_posts_page_link($cur_page) { if ( $cur_page > 1 ) { $nextpage = intval($cur_page) - 1; if ( $nextpage < 1 ) $nextpage = 1; return '<a href="' . get_pagenum_link($nextpage) . '">« previous listings</a>'; } } function wight_get_next_posts_page_link($cur_page, $max_page) { $paged = $cur_page; if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( $max_page >= $nextpage ) return '<a href="' . get_pagenum_link($nextpage) . '">next listings »</a>'; }
used in place of previous_posts_link , next_posts_link.
<?php echo wight_get_previous_posts_page_link($cur_page); ?> <?php echo wight_get_next_posts_page_link($cur_page, $query->max_num_pages); ?>
Comments
Post a Comment