-
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
Add more taxonomy options to the post navigation link #48912
Conversation
Size Change: +202 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
Flaky tests detected in 54a58bb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6770650485
|
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've tested this out and it's working well for me 🎉
- You should be able to navigate to the second post in the birds category, and from there, to the third post in the birds category. ✅
- When viewing the third post, the "next" link should not show. ✅
- The next link should link to post number four that you just created, post 2 and 3 should be excluded. ✅
- Only the taxonomies supported by the post type should show in the taxonomy option. ✅
I've left some minor inline comments.
Perhaps the toggle label should be “Filter by taxonomy” |
Yes! Much better. |
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.
Looks good to me!
What we could do is move one or both settings to the Advanced panel. |
I was thinking something like this: block.json:
In And then to turn the filter off and set defaults:
I haven't gotten it to work yet; If the block already has a term added to the |
@WordPress/block-themers Hi people, I would appreciate your thoughts about this feature and the suggestion from August 11 (above) about allowing it to be disabled. |
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 think this is a great addition to this block!
.filter( | ||
( tax ) => | ||
tax.slug !== 'nav_menu' && | ||
tax.slug !== 'wp_pattern_category' |
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.
The pattern category shows in the option in Site Editor unless it is removed here.
If the "New admin views" Gutenberg experiment is enabled, data views also show in the option. I did not hide it since it is still experimental.
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.
Is this conditional statement really necessary? I hesitate to hardcode specific taxonomy slugs into blocks. For example, in a query loop block, no such condition exists.
gutenberg/packages/block-library/src/query/utils.js
Lines 130 to 144 in 55b4e9b
export const useTaxonomies = ( postType ) => { | |
const taxonomies = useSelect( | |
( select ) => { | |
const { getTaxonomies } = select( coreStore ); | |
const filteredTaxonomies = getTaxonomies( { | |
type: postType, | |
per_page: -1, | |
context: 'view', | |
} ); | |
return filteredTaxonomies; | |
}, | |
[ postType ] | |
); | |
return taxonomies; | |
}; |
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 simply deleted the filter and nothing changed in the interface. I am not sure what changed since November but neither the nav menu, pattern categories or the admin views are showing up now. Custom taxonomies, for standard and for custom post types are showing correctly as well.
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 don't know about the navigation menu and admin view, but it seems that public
has been changed to false
in the pattern category.
setAttributes( { | ||
taxonomy: value, | ||
inSameTerm: value === '' ? false : true, | ||
} ) |
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.
The value of isSameTerm
depends only on whether the value of taxonomy
is empty. So, can this attribute be removed and not determined during dynamic rendering?
@draganescu can you revert the commit? I'd rather not deal with another deprecation. |
It is disheartening to work on something for close to a year and not receive code reviews until commit, it has become quiet difficult to find willing reviewers the past 6 months, -and it is not a problem with one pull request but most of them. All I can do is ping people. |
I want to contribute to the project on issues that matter and are on the roadmap, not work on things that are not worthy peoples time to review. |
If I understand correctly, this block is a dynamic block, so if we don't need to migrate existing attributes, I think we don't need the deprecation, and we don't need to revert. If there is something that can be improved, I think it would be a good idea to commit to it as a follow-up. |
Then I hope that with both your help I can fix it before 17.6. |
What?
Updated Nov 6 2023.
This PR adds support for two parameters of get_next_post_link / get_previous_post_link that were not supported by the block.
$in_same_term bool Optional
Whether link should be in a same taxonomy term.
Default: false
$taxonomy string Optional
Taxonomy, if $in_same_term is true. Default 'category'.
Default: 'category'
Closes #47090
Why?
The features are available in classic themes but were missing from the block. The feature allows site creators and developers to limit what should be included as a next and previous link.
This allows site creators to for example add a 'news' category to some posts, and only link to the other posts in this category.
How?
Adds a select list with taxonomies under the Advanced panel. Selecting a taxonomy in this list will limit the next and previous links.
To get a list of all supported taxonomies, including custom taxonomies, we need to know the post type.
I was not able to find any other way to get the post type besides using the core editor store.
If you know of a better way please comment on the PR.
Testing Instructions
Create three identical posts:
Add the posts to the "birds" category, or any new category that you want to add for the test.
Add the next and previous post navigation link blocks. Open the advanced panel and select category as the taxonomy.
View the first post on the front.
You should be able to navigate to the second post in the birds category, and from there, to the third post in the birds category.
When viewing the third post, the "next" link should not show.
Register a custom post type and custom taxonomy. The fastest way to do this is to enable a plugin with custom post types, I used https://wordpress.org/plugins/yoast-test-helper/.
Repeat the testing instructions above but use the custom post type and custom taxonomy (movie and genre for example).
Only the taxonomies supported by the post type should show in the taxonomy option.
Next, with a block theme active, please test the block in the Site Editor:
Go to Appearance > Editor > Templates, and edit the single post template.
Select or add the post navigation link blocks, and enable the filter under the Advanced panel.
Save the template changes.
Confirm that the placeholder in the Site Editor is the same, and that the correct posts are linked on the front of the website.
Screenshots or screencast