简体   繁体   English

在WordPress页面中使用WordPress进行分页

[英]pagination with wordpress in wordpress page

I have made testimonial page in wordpress. 我在wordpress中做了推荐页。 data is coming from database dynamically.I want to do paging in that page.can any one suggest me the proper way to achieve my goal? 数据是动态地来自数据库的。我想在该页面中进行分页。有人可以建议我实现目标的正确方法吗?

The WordPress $post object that is passed along with every page can help you out. 与每个页面一起传递的WordPress $post对象可以为您提供帮助。 You need to tell WordPress that while building up the list of posts, it need to take into account the page that it's on. 您需要告诉WordPress,在建立帖子列表时,需要考虑其所在页面。

To make sure that's happening, you need to adjust your page's wp_query. 为了确保这种情况发生,您需要调整页面的wp_query。 What you want to do is modify the current query, but change nothing else. 您想要做的就是修改当前查询,但别无更改。

As the documentation puts it: 正如文档所述:

query_posts() is meant for altering the main loop. query_posts()用于更改主循环。 Once you use query_posts(), your post-related global variables and template tags will be altered. 一旦使用query_posts(),与帖子相关的全局变量和模板标签将被更改。 Conditional tags that are called after you call query_posts() will also be altered - this may or may not be the intended result. 调用query_posts()之后调用的条件标签也将被更改-这可能是也可能不是预期的结果。

If that's what you're after, the following code-snippets below allows you to do just that. 如果您要这样做,可以使用下面的代码段来做到这一点。

query_posts(
  array(
    'paged' => get_query_var('paged')
  )
);

If you are using a custom page template to list posts, however, you want to use a slightly different snippet (note the variable's missing 'd'): 但是,如果您使用自定义页面模板列出帖子,则要使用稍有不同的代码段(请注意变量缺少的“ d”):

query_posts(
  array(
    'paged' => get_query_var('page')
  )
);

Alsol here's some more explanation by the author of the PageNavi plugin, and if you'd like to know more about what wp_query can do, check out the WordPress Codex page for query_posts . Alsol 这是 PageNavi插件作者的更多解释 ,如果您想进一步了解wp_query可以做什么,请查看WordPress Codex页面中的query_posts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM