WordPress博客分页问题,从第3页开始给出错误404
该代码的这一部分是从博客的第03页引起的404。 我已经尝试更改配置并将其与代码相同,但它仍然不起作用。当有7个以上的帖子时,这种情况正在发生。
@php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_per_page = is_paged() ? 6 : 7;
$args = [
'post_type' => 'post',
'posts_per_page' => $posts_per_page,
'paged' => $paged
];
if ($category) {
$args['tax_query'] = [
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $category->slug,
]
];
}
if ($search) {
$args['s'] = $search;
}
$i = 1;
@endphp
This part of the code is causing the 404 from page 03 of the blog.
I've already tried to change the configuration and make it the same as the code, but it still doesn't work. This is happening when there are more than 7 posts.
@php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_per_page = is_paged() ? 6 : 7;
$args = [
'post_type' => 'post',
'posts_per_page' => $posts_per_page,
'paged' => $paged
];
if ($category) {
$args['tax_query'] = [
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $category->slug,
]
];
}
if ($search) {
$args['s'] = $search;
}
$i = 1;
@endphp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想跳过帖子中的前三个帖子查询,则可以在查询 args 中使用
'offset'
。此外,如果您想查询页面,则帖子类型需要为
page
。我认为您会遇到一个错误,因为您在查询帖子而不是页面,因此可能找不到404。
If you want to skip the first three posts in your posts query, you can use
'offset'
in your queryargs
.Moreover if you want to query pages, the post type needs to be
page
.I think you get an error because you are querying posts and not pages, so there might be the 404 not found.