我正在尝试为一些自定义帖子类型分页,前面的链接可以工作,但下一个链接不行。我尝试了几种方法,但都找不到正确的方法。。。如果有人能帮忙:)
这是我的代码:
function livredor_function($atts,$content=\'\'){
extract(shortcode_atts(array(
id => \'\'
), $atts));
ob_start();
function create_guestbook() {
$i = 1;
$max_entries_per_page = 0;
$current_page = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 0;
$gbquery = new WP_query("post_type=inliguestbook&showposts=10&paged=" . $current_page);
while($gbquery->have_posts()) { $gbquery->the_post();
?>
<div class="guestbook">
<h3><?php the_title(); ?> <span><?php the_time(\'j F Y\') ?></span></h3>
<?php the_content(); ?>
</div>
<?php
$i++;
}
?>
<div class="pagenav">
<div class="pagnext"><?php next_posts_link(\'—›\', $max_entries_per_page) ?></div>
<div class="pagprev"><?php previous_posts_link(\'‹—\', $max_entries_per_page) ?></div>
</div>
<?php
}
$gbquery = null; $gbquery = $temp;
wp_reset_query();
return create_guestbook() . ob_get_clean();
}
add_shortcode(\'livredor\',\'livredor_function\');
SO网友:DavidP
好的,谢谢你的ialocin,$gbquery->max\\u num\\u页面解决了这个问题!
所以有一个干净的代码:
function livredor_function($atts,$content=\'\'){
extract(shortcode_atts(array(
id => \'\'
), $atts));
ob_start();
function create_guestbook() {
$current_page = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 0;
$gbquery = new WP_query("post_type=inliguestbook&showposts=10&paged=" . $current_page);
while($gbquery->have_posts()) { $gbquery->the_post();
?>
<div class="guestbook">
<h3><?php the_title(); ?> <span><?php the_time(\'j F Y\') ?></span></h3>
<?php the_content(); ?>
</div>
<?php
}
?>
<div class="pagenav">
<div class="pagnext"><?php next_posts_link(\'—›\', $gbquery->max_num_pages) ?></div>
<div class="pagprev"><?php previous_posts_link(\'‹—\', $gbquery->max_num_pages) ?></div>
</div>
<?php
}
wp_reset_query();
return create_guestbook() . ob_get_clean();
}
add_shortcode(\'livredor\',\'livredor_function\');