admin管理员组文章数量:1389865
I'm working on a custom theme based on Underscores. In my archive.php
I want to style the first post in the loop differently than the rest, so I'm running one WP_Query
to fetch the first post, and another to get the remaining posts.
What I'm wondering is -- since I'm handling the queries myself, what happens to the default query that WordPress is running implicitly (that is, the one I'd normally be iterating over with while ( havePosts() )
? Obviously for performance reasons I don't want to run any unnecessary queries, so is there a way I can stop it?
I'm somewhat familiar with the pre_get_posts
hook, but I'm not sure how I would use it since, as I mentioned, I'm not just trying to modify the one default query -- I need two (unless there's a better way of doing this).
I'm working on a custom theme based on Underscores. In my archive.php
I want to style the first post in the loop differently than the rest, so I'm running one WP_Query
to fetch the first post, and another to get the remaining posts.
What I'm wondering is -- since I'm handling the queries myself, what happens to the default query that WordPress is running implicitly (that is, the one I'd normally be iterating over with while ( havePosts() )
? Obviously for performance reasons I don't want to run any unnecessary queries, so is there a way I can stop it?
I'm somewhat familiar with the pre_get_posts
hook, but I'm not sure how I would use it since, as I mentioned, I'm not just trying to modify the one default query -- I need two (unless there's a better way of doing this).
1 Answer
Reset to default 2WordPress always queries a default set of posts when you view any sort of archive. So if you run your own query as described you’ll end up with 3 database queries instead of 1.
You should not develop your template the way you describe. The standard WordPress templates should all use the default query. You’ll be coming back as the 400th person to ask why pagination isn’t working properly if you do it this way, among other potential issues. If you want to style the first post differently there are plenty of ways to do that without querying it separately, from CSS techniques to logic in the template. If you have something specific you’re trying to accomplish, I suggest posting a new question with those details.
本文标签: theme developmentWhat happens to the default query when I use WPQuery
版权声明:本文标题:theme development - What happens to the default query when I use WP_Query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744639713a2617046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论