这是我的函数文件
add_action( 'wp_ajax_homekong_pagination', 'homekong_pagination' );
add_action( 'wp_ajax_nopriv_homekong_pagination', 'homekong_pagination' );
function homekong_pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "";
echo "";
echo "";
if($paged > 2 && $paged > $range+1 && $showitems < $pages)
echo "PREVIOUS";
if($paged > 1 && $showitems < $pages)
echo "";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "".$i."" : "".$i."";
}
}
if ($paged < $pages && $showitems < $pages)
echo "";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages)
echo "NEXT";
echo "";
echo "";
echo "";
}
exit();
}这是我希望更改发生的前端代码。
'publish_date',
'order' => 'desc',
'post_type' => 'blogs',
'paged' => $paged,
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
have_posts() ): ?>
have_posts() ) : $the_query->the_post(); ?>
ID, 'blog-category');?>
如何将ajax添加到分页中?我想不出一条出路发布于 2019-09-13 09:04:52
要做到这一点,只需在javascript中发出一个ajax请求即可。
这是一个逐步的解决方案。
jQuery(document.body).on('click', '#pagination a', function (event) {
var linkElement = jQuery(event.currentTarget);
jQuery.ajax(linkElement.attr('href')).done(function (newPageHTML) {
jQuery('.blog-items').replaceWith(
jQuery(newPageHTML).find('.blog-items')
);
});https://wordpress.stackexchange.com/questions/348207
复制相似问题