【发布时间】:2018-04-09 10:41:39
【问题描述】:
我想对 AJAX 请求的结果进行分页。分页不起作用。点击页码后,只有地址和所有内容(例如:/page/3/)发生变化。我哪里做错了?
PAGE.PHP
<div class="site-content clearfix">
<h1>Alex Blog</h1>
<?php
$ourCurrentPage = get_query_var('paged');
$aboutPosts = new WP_Query(array(
'post_type' => 'tour',
'post_status' => 'publish',
'posts_per_page' => 3,
));
if ($aboutPosts->have_posts()) :
while ($aboutPosts->have_posts()) :
$aboutPosts->the_post();
?>
<span> <?php the_title(); ?> </span>
<br>
<?php endwhile;
echo paginate_links(array(
'total' => $aboutPosts->max_num_pages
));
endif;
?>
</div>
FUNCTION.PHP
function tourcat_ajax_by_order() { if (isset($_REQUEST)) {
$posts_per_page = et_get_option( 'divi_archivenum_posts' ) ;
$args = array( // WP query args
'post_type' => 'tour',
'post_status' => 'publish',
'posts_per_page' => $posts_per_page
);
$tour_query = new WP_Query($args);
if ( $tour_query->have_posts() ) { // Have posts start here
while ( $tour_query->have_posts() ) { // While starts here
$tour_query->the_post();
?>
<span> <?php the_title(); ?> </span>
<br>
<?php}
echo paginate_links(array(
'total' => $aboutPosts->max_num_pages
));}
else {
echo 'No results found';}
wp_reset_postdata();}
die();}
JS 代码
function tourcat_orderby_posts() {
$.ajax({
url: ajaxurl,
data: {
'action':'tourcat_ajax_by_order',
},
success: function(data) {
// This outputs the result of the ajax request
$(".tour_parent_div").html(data);
},
error: function(errorThrown) {}
});}
【问题讨论】:
-
不知道。你检查过你是否真的得到了正确的价值观吗?例如,页码可能永远不会到达您的 PHP 代码吗?或者确实如此,但不是
paged。如果这行得通..您实际上在哪里使用$ourCurrentPage? -
也显示JS代码。
-
lab.mark5designs.com/alex 我的网站。请看。
-
你没有在分页上使用页面 ajax。
-
我对 AJAX 请求使用分页。
标签: php ajax wordpress pagination