admin管理员组文章数量:1384426
I'm working on a site where the client wants only the linked titles of all posts in a particular category on one page. That is, the query does not pick up the smaller number of posts that is defined in Settings from that one particular template.
I could do this if I by-pass the loop entirely, but is it possible within the normal loop?
I'm working on a site where the client wants only the linked titles of all posts in a particular category on one page. That is, the query does not pick up the smaller number of posts that is defined in Settings from that one particular template.
I could do this if I by-pass the loop entirely, but is it possible within the normal loop?
Share Improve this question asked May 17, 2020 at 21:15 Nora McDougall-CollinsNora McDougall-Collins 3952 silver badges15 bronze badges1 Answer
Reset to default 2The best way to do this is to use the pre_get_posts
filter, which changes the main query. That way you're not running the default query plus a custom one on top of it. You'll have to determine the "if" conditions to only run on the query you want to affect:
<?php
function wpse_366882_get_all_posts($query) {
// This will run for all main queries that are not in wp-admin.
// You may want "is_archive()", "is_page('slug')" or some other condition.
if ( ! is_admin() && $query->is_main_query() ) {
// Setting to -1 shows all.
$query->set( 'posts_per_page', -1 );
}
}
add_action( 'pre_get_posts', 'wpse_366882_get_all_posts' );
?>
You can place this code in a custom plugin, or in a custom theme or child theme's functions.php
file.
本文标签: customizationIs there a way to bypass the pagination function on one custom template
版权声明:本文标题:customization - Is there a way to by-pass the pagination function on one custom template? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744464346a2607424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论