admin管理员组

文章数量:1122846

I have created a page that is set as my "Posts Page" in the "Reading" settings. On that page I have added a Gutenberg block but it doesn't show up on the page so long as I have the page set as the "Posts Page." Is there any way for me to have that Gutenberg block show up above the post list using the index.php template instead of creating a custom page template with a post loop to use as my blog page?

I have created a page that is set as my "Posts Page" in the "Reading" settings. On that page I have added a Gutenberg block but it doesn't show up on the page so long as I have the page set as the "Posts Page." Is there any way for me to have that Gutenberg block show up above the post list using the index.php template instead of creating a custom page template with a post loop to use as my blog page?

Share Improve this question asked Aug 30, 2024 at 17:05 user13286user13286 2272 gold badges12 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2 +50

You could add something like this before the while()-loop in your index.php:

// only if we are on the posts page
if ( is_home() ) {

    // global post record
    global $post;

    // get the posts-page record
    $post = get_post( get_option( 'page_for_posts' ) );

    // set it up as the global $post
    setup_postdata( $post );

    // content output, cheaply wrapped
    echo '<div class="posts-page-content">';
    the_title();
    the_content();
    echo '</div>';

    // restore the post data to the original one
    wp_reset_postdata();
}

Then you propably have to add some lines of CSS to look it nice and clean.

本文标签: theme developmentDisplay Gutenberg blocks from quotPosts Pagequot above the post list