Opened 15 years ago
Closed 15 years ago
#10822 closed defect (bug) (invalid)
Post page is 404 when no post found on static page for homepage
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8 |
Component: | Query | Keywords: | is_posts_page |
Focuses: | Cc: |
Description
On front page configuration, I specify 2 static pages, one for homepage (ex: page1), and another for posts page (ex: page2).
If I have no post, page2 is like a 404 page.
The $wp_query is well parsed, but on handle_404() call, no test on $wp_query->is_posts_page flag is available (like category or tag query).
The handle_404 test change the $wp_query setting and it's not possible to know if we are in posts_page or not(is_404 = true and is_posts_page = false).
is_post_page is not used a lot in the source code, I haven't found an is_posts_page() global function.
So we can had it :
function is_posts_page() {
global $wp_query;
return ($wp_query->is_posts_page);
}
and in handle_404 of wp-includes/classes.php (line 464 on 2.8) change the line
is_category() | is_author() ) && $wp_query->get_queried_object() ) { |
by
is_category() | is_author() | is_posts_page()) && $wp_query->get_queried_object() ) { |
It's seem that the problem is only available with this configuration. No problem if I use same homepage and post_page.
You could be searching for the function is_home() here.
Also, when there are no posts found for the blog index WP doesn't issue a 404, it calls the theme's index.php in which have_posts() will return false. Therefore, are you sure the 404 you are seeing is not a result of your theme's index.php.