【发布时间】:2015-11-30 12:56:37
【问题描述】:
我使用 _S 入门主题从头开始开发自定义主题。我在单击阅读更多按钮时通过 ajax 请求获取 Wordpress 下一篇文章时遇到问题。我已经尝试了很多文章,特别是以下文章,但没有运气。
参考链接:
-
Load More Posts Ajax Button in Wordpress
-
Load Next WordPress Posts With AJAX
- Load Old WordPress Posts on the Same Page with AJAX
我尝试过使用上述自定义循环并使用 jquery 脚本添加自定义函数,但它无法以某种方式工作。
下面是循环代码示例:
在 index.php 中循环
<?php query_posts('showposts=5'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="post-item">
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; ?>
<?php else : ?>
<h2>Sorry no posts are created yet.</h2>
<p>Please create some posts to see it in action.</p>
<?php endif; wp_reset_query(); ?>
<button class="load-more-btn">Load More</button>
我已经解决这个问题超过 4-5 天了,所以任何人都可以通过有效的解决方案帮助我解决这个问题。
提前致谢。
【问题讨论】:
-
如果您不介意为此使用插件:stackoverflow.com/questions/20167896/…
-
您好 Clyff 感谢您的回复。我已经尝试过这个插件,甚至试图修改它以使其工作,但是通过这样做,我的“加载更多”按钮消失了,因为我将“posts_per_page”设置为 5,并且我的 wp 中有超过 5 个帖子。
-
插件名称为 PBD Ajax Load Posts
-
我也不想使用无限循环,因为它会通过转到页面底部来自动触发。相反,我更喜欢在点击时触发它。
标签: php jquery ajax wordpress twitter-bootstrap-3