-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Home.html displays title from query loop instead of post-title #39187
Comments
@ntsekouras Nik perhaps you can take a look at this issue? |
I have the same issue. Following a theme creation tutorial found at fullsiteediting dot com. Very, very blank theme. No dependencies, all plugins on or off same result. (there only is query monitor, gutenberg and woo) In my case this is in page.html
I get 'Hello World' instead of the single page title when viewing siteurl.local/pagetitle |
If you want this to work just create a page template named Just go to the edit or quick edit page and choose your page-blog template as it now appears in the page template selector, thanks to the nomenclature It is worth remembering that you will need a query Loop block. |
Thanks for the tip. I'm aware that this is possible, we can put query loops on every page and call it a blog page. But I've put this issue up to help make sure new WordPress adheres to its own template hierarchy in a consistent (and familiar) manner. |
Sure. |
@Humanify-nl Thank you for opening this again. I saw your other one that was closed and then found this one. This will be helpful for those of us writing hybrid themes or updating a classic theme to play more nicely with WP 5.9 features. I've made page and archive header patterns for my theme and this issue affects their use. I insert the block pattern with the post title in the page that displays blog posts and it looks fine. But when I go to the front end, it displays the title of the first post in the loop. |
I did some testing right now and it seems that the results are the same even without a Query Loop block. Also noting that if you set the same page as It might be something with the Post Title block and or Posts page setting.. |
I have tested this issue again and it appears that this problem occurs with the post-title block alone. The simplest procedure to reproduce the issue is described below.
<!-- wp:post-title /-->
|
I have looked into this issue more deeply and expect the problem to be due to the context (
|
I believe this is a core issue. In the block theme, the page IDs do not appear to be set correctly in the following locations: |
Great investigation! As far as I can remember it is hard to get post ID on the site editor side in the template screen. This might be why this is not (yet) working as intended. This might be related to issue: #42810, as this is a similar case where not being able to get post_id is mentioned. See comment there, third paragraph |
I workaround this by adding an heading-block which mimics the post-title-block to the index.html-template:
Then in the Site Editor users can change "Blog" to another name. |
This fails when using When assets are loaded per block on the page, heading styles will be applied instead of post-title. Which is something to be aware of when these differ in your project. |
Ran into same issue today. My workaround: // functions.php
register_block_type( "custom/page-title", [
"render_callback" => function () {
return get_the_title( get_option("page_for_posts") );
},
] ); <!-- home.html -->
<!-- wp:custom/page-title /--> |
Similarly you can create custom block for blog page content: // functions.php
register_block_type( "custom/page-content", [
"render_callback" => function () {
return get_the_content( null, false, get_option("page_for_posts") );
},
] ); <!-- home.html -->
<!-- wp:custom/page-content /--> |
This is another possible solution:
This is using the Query Title (or archive title) It makes it possible to get all the alignments font sizes etc goodies from the query tite block, (without re-writing the entire block) and also means you can use the same template.html for the archive pages as the blog page if you wish. |
Description
As I am aware, assigning any page as the 'blog page' in WP reading settings, this will load home.php / home.html in the template hierarchy. This is the specific use case here.
In the home.html template, we want to add a post-title to the blogpage template, or in a template-part assigned to the home.html.
Problem: The title displays the title of first post in the loop. Not the page title (which is 'blog' in my case). The featured image block also displays the first posts' featured image, and the not the blogs (or none if it isnt assigned).
Expectation: It should display the title of the current page, not a post in the query loop.
I remember in the 'old days' this was a bug that occured when 'wp_reset_postdata' wasn't used correctly to close the loop. But i assume it works a little different in a block theme.
@everyone: this can be solved with manually placing a heading block, but the purpose of issues here is that we want this to work as expected or intended.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Testing with post title in the 'header-dark-small' template-part:
Testing with post-title in the template itself:
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: