为所有帖子构建滑块
在我的网站标题中,我有一个包含 6 个最新帖子的水平列表。现在我想添加一个“上一篇”按钮,这会导致此列表的内容被当前显示的之前的 6 篇文章替换。这个想法是,如果用户足够频繁地点击“上一个”,他就能够看到曾经发布的所有帖子。
大多数创建这个的教程总是加载所有帖子,然后简单地将它们填充到一些 jQuery 滑块中。然而,由于我有 100 多篇帖子,这似乎不是最好的方法(有些用户实际上可能根本不会点击“上一篇”,所以为什么要浪费资源加载它们)。
您能给我指点一个教程,解释如何在每次单击“上一页”按钮时使用 php 获取以前的帖子吗? (顺便说一句,我正在使用 Wordpress)
这个问题在没有任何教程的情况下就得到了解决,只是在一些 stackoverflow 线程的帮助下。现在我有了一个很棒的 Post-Slider :)
In the header of my website, I have a horizontal list of the 6 latest posts. Now I would like to add a "previous" button, which causes the content of this list to be replaced by the 6 posts before the ones that are currently displayed. The idea is that, if a user clicks "previous" often enough, he is able to thereby see all posts ever made.
Most of the tutorials for creating this always load ALL posts, and then simply stuff them into some jQuery-slider. However, since I have 100+ posts, this seems not the best approach (some users might actually never click "previous" at all so why waste resources loading them).
Could you please point me to a tutorial that explains how I can get the previous posts using php each time the "previous" button is clicked? (I'm using Wordpress btw)
The problem was solved without any tutorial, just with the help of a few stackoverflow threads. Now I have an awesome Post-Slider :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您依赖 php 来实现这一点,则每次都需要刷新页面。我认为您确实想要一个 AJAX 解决方案。
您可以构建一个 PHP Web 服务,该服务
1) 接受一些变量,例如当前显示的最低帖子的 ID
2) 输出之前的 6 个帖子的 XML 或 JSON 然后
,在您的页面上,
onclick
上一个按钮,发送变量,接受响应,然后根据需要放置每个帖子。.ajax
和.load
是一些需要研究的 jQuery 方法If you rely on php for that, you'll need to refresh the page each time. I think you really want an AJAX solution.
You can build a PHP web service that
1) accepts some variable, such as the ID of the lowest post currently displayed
2) outputs XML or JSON of the six posts prior to that
Then, on your page,
onclick
of your previous button, send the variable, accept the response, and place each post as needed..ajax
and.load
are some jQuery methods to look into