我有一个自定义的帖子类型插件,它通过一个短代码来引入所有的帖子。所有这些都运行得很好。我希望能够通过jquery对返回的帖子进行分页,并尝试了在线教程中的各种方法。过去的两天是痛苦的。
我的代码是:
function xma_display_stores() {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 2;
$args = array('post_type' = > 'stores', 'orderby' = > 'title', 'order' = > 'asc', 'posts_per_page' = > $paged);
$success = new WP_Query($args);
$output = '';
$output. = sprintf("<table class='stores'>");
$output. = sprintf("<tr><th>File Name</th><th>Date added</th><th>Download</th></tr>");
while ($success - > have_posts()) {
$success - > the_post();
$output. = sprintf("<tr>");
$output. = sprintf("<td>%s</td>", get_the_title());
$output. = sprintf("<td>%s</td>", get_the_date());
$output. = sprintf("<td>%s</td>", wp_get_attachment_link());
$output. = sprintf("<tr>");
}
$output. = sprintf("</tr></table>");
$output. = sprintf("<p>%s</p>", next_posts_link('Next set'));
$output. = sprintf("<p>%s</p>", previous_posts_link('Prev set'));
return $output;
}
add_shortcode('display_stores', 'xma_display_stores');发布于 2013-12-21 16:36:59
将您的$paged和$args版本替换为:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' = > 'stores', 'orderby' = > 'title', 'order' = > 'asc', 'paged' => $paged );posts_per_page决定在一个页面上显示多少帖子,而不是显示哪个页面的帖子。
还要将$success->max_num_pages作为第二个参数添加到next_posts_link中,这样:
$output. = sprintf( "<p>%s</p>", next_posts_link( 'Next set', $success->max_num_pages ) );https://stackoverflow.com/questions/20702993
复制相似问题