Opened 11 years ago
Last modified 3 months ago
#30705 new enhancement
Add parameter to get_the_term_list() to allow templating
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.5 |
Component: | Taxonomy | Keywords: | has-unit-tests needs-refresh |
Focuses: | Cc: |
Description (last modified by )
Similar to #27238 the parameter $term_template is suggested to allow for user created formatting for get_the_term_list(), as opposed to the previous standard of simply linking to each list in the term.
The reasoning for the change is that general linking is not always the desired action for displaying term lists. The method for inclusion is similar to [30209].
Attachments (1)
Change History (10)
#4
@
10 years ago
- Keywords needs-unit-tests needs-patch added; has-patch removed
- Milestone changed from Awaiting Review to Future Release
Would like to see unit tests for this. Also, if we're going to add support here, we should also add it to functions that call get_the_term_list()
- namely, get_the_tag_list()
.
#5
@
4 months ago
A proposal was made to display categories and tags without links in the Gutenberg Post Terms block.
The Post Terms block uses get_the_term_list()
function internally, so I think this is related to this ticket.
This ticket was mentioned in PR #8393 on WordPress/wordpress-develop by @sukhendu2002.
4 months ago
#6
- Keywords has-patch has-unit-tests added; needs-unit-tests needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/30705
#7
@
4 months ago
There already are multiple functions for displaying the terms without links, please document what the benefit of this change would be.
#8
@
3 months ago
- Keywords needs-refresh added; needs-testing has-patch removed
Test Report
Description
This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8393.diff
Environment
- WordPress: 6.8-beta3-60042-src
- PHP: 8.2.28
- Server: nginx/1.27.4
- Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.28)
- Browser: Chrome 134.0.0.0
- OS: Windows 10/11
- Theme: Twenty Nineteen 3.0
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Actual Results
- ✅ Issue resolved with patch.
- ✅ Unit tests are passing correctly.
Only one unit test: test_get_the_term_list_custom_template
is testing the current patch, the other two are released a little out of context, but its always good to have extra coverage, although the first one could be a good reminder to avoid accidentally removing the fallback default value for the new $get_the_term_list
value
- ❌ Missing all doc comments in the
tests/phpunit/tests/term/termTemplate.php
, please review.
Additional Notes
@sukhendu2002 provided a solution to the Gutenberg report @wildworks is suggesting
https://github.com/WordPress/gutenberg/pull/69273/
That doesn't really require editing this function.
As @poena has mentioned: Although there is a patch that has be tested, this report requires an use-case
that can illustrate why this can be an useful thing in 2025.
#9
@
3 months ago
It is of course possible to display terms related to a post without links. For example:
<?php $terms = get_the_terms( get_the_ID(), 'taxomomy_name' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?> <ul> <?php foreach( $terms as $term ) : ?> <li><?php echo esc_html( $term->name ); ?></li> <?php endforeach; ?> </ul> <?php endif; ?>
Wouldn't it be convenient if we could achieve the same thing with code like this:
echo get_the_term_list( get_the_ID(), 'taxomomy_name', '<ul><li>', ',</li><li>', '</li></ul>', '%2$s' // Default is `<a href="%1$s" rel="tag">%2$s</a>` );
inclusion of $term_template argument