You can use:
-
get_queried_object_id()
to get the ID of the static posts Page. Alternatively, you may also useget_option( 'page_for_posts' )
.$post_id = get_queried_object_id(); //$post_id = get_option( 'page_for_posts' ); // you should use the above on the blog page $content = get_the_content( null, false, $post_id );
-
get_queried_object()
to get the full data of the static posts Page. (You’d get an object just as the one returned byget_post()
.)$post = get_queried_object(); $content = get_the_content( null, false, $post ); // or you could use $post->post_content
And on the posts page, the global $wp_query
(the main query) already contains the latest/blog posts, so there is no need to make a secondary query like the $wpb_all_query
in your code. Just use the main loop to display the posts and you can use the pre_get_posts
hook to alter the main query, e.g. to change the number of posts queried per page.
So your home.php
template could be as simple as:
<?php get_header(); ?>
<h1><?php single_post_title(); ?></h1>
<?php
// Display the content of the static posts Page.
// This is just an example using setup_postdata().
$post = get_queried_object();
setup_postdata( $post );
the_content();
wp_reset_postdata();
?>
<?php
// Display the latest/blog posts.
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php
endwhile;
endif;
?>
<?php get_footer(); ?>