-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Post template: Adjust the editor preview on taxonomy archive templates #66595
Conversation
Size Change: +77 B (0%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Flaky tests detected in c3ca902. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11593122829
|
Why do we need to do this?
Also I was searching for this. Do you have any link to share what is the slug for post formats according to template hierarchy? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find much info about the slugs of post format templates (my previous comment), but tested and seem to work as expected.
In my initial testing on a fresh WordPress install, I found that if I did not change the permalinks, the wrong posts were shown on the front. The documentation for the file names is in the Theme Developer Handbook: |
What?
This pull request adds two conditions to the edit.js file in the post template block, to ensure that the
preview in the editor shows the correct posts on tag and post format templates.
Closes #65320
Why?
Archive templates for tags and post formats showed the wrong posts in the editor when the query loop was set to inherit (Query type: Default). Instead of listing the posts that are assigned the tag or format, it showed the latest posts.
How?
If a the template slug starts with
tag-
, the id of the tag is fetched usinggetEntityRecords
. The ID is then added to the query, and the correct posts are returned and shown in the preview.This is identical to the current solution for the category templates.
If a template slug starts with
taxonomy-post_format
, the format is collected from the template slug and added to the query.Testing Instructions
Activate a block theme.
Create a new post with a tag.
Go to Appearance > Editor > Templates.
Select "Add new template", then "Tag Archives" and "for a specific item".
Create the new template for the tag you added to your post.
Now depending on your theme you should be able to select a pattern for an archive,
this pattern will include query loops and post template blocks.
If not, you will need to add these blocks.
Just to be sure, double check that the query loop is set to "Query type: Default". Not custom.
Confirm that the preview in the editor shows post(s) with the correct tag.
To test the post format archive, you need a theme that has supports for post formats.
If your theme is missing this feature, register post formats by adding this example code to the theme's functions.php file.
Set the permalinks on the test installation to Post name.
Create a few posts and assign them the link post format.
Next, add a link post format archive template inside the theme's templates folder.
templates/taxonomy-post_format-post-format-link.html
Go to Appearance > Editor > Templates, locate and edit the template.
Add a query loop block. In the block settings sidebar, make sure that "Query type: Default" is enabled.
Check if the query loop shows the correct posts, it should only show the posts that you assigned the link format to.
Save.