【发布时间】:2017-03-08 04:11:47
【问题描述】:
对于显示为 ajax 响应的帖子,我正在尝试进行页面导航。
我不确定如何完成此操作。
这里有一些代码可以查看。
$posts_per_page = 6;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$pageposts = query_posts(
array(
'post_type' => 'post',
'cat' => intval($_POST['pageCategory']),
'paged' => $paged,
'posts_per_page' => $posts_per_page,
));
if ($pageposts):
$response = '';
foreach ($pageposts as $post):
$postId = get_the_ID();
$postPermalink = get_the_permalink($postId);
$postTitle = get_the_title();
$response .= '
<article class="gridView col-lg-4 col-md-6 col-xs-12">
<div class="list-article-thumb" style="background: url('; if ( get_the_post_thumbnail_url() == false ) { $response .= get_stylesheet_directory_uri() . '/images/placholder2.png'; } else { $response .= get_the_post_thumbnail_url(); } $response .= ') no-repeat; height: 445px; background-size: cover; position: relative;">
</div>
</article>
';
endforeach;
$response .= wp_pagenavi();
wp_reset_query();
else :
$response = '
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn\'t here.</p>
';
endif;
页面导航作为 ajax 请求的一部分返回,但是当我单击下一页按钮时,它会转到该页面,而不是向 ajax-posts.php 发送另一个请求
朋友们加油
【问题讨论】:
-
“我点击下一页按钮会转到该页面”——您是否停止了默认事件在点击该按钮时触发?
-
没有页面加载正常,但它带我到页面
http://localhost/testwp2/wp-content/themes/my-theme/ajax-posts.php/page/2/但该页面不存在,因为 ajax-posts.php 是处理 ajax 请求并返回上述代码的页面$响应变量 -
我认为我要做的是在响应中使用 js 构建自己的分页,但希望使用插件让生活更轻松。
-
所以你是说你不想被带到那个页面对吗?您需要 Ajax 继续触发并忽略按钮单击事件吗?
-
是的,就是这样
标签: javascript php ajax wordpress plugins