Make WordPress Core

Opened 11 years ago

Last modified 3 months ago

#30705 new enhancement

Add parameter to get_the_term_list() to allow templating

Reported by: davidjlaietta's profile davidjlaietta Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Taxonomy Keywords: has-unit-tests needs-refresh
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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)

category-template.diff (1.2 KB) - added by davidjlaietta 11 years ago.
inclusion of $term_template argument

Download all attachments as: .zip

Change History (10)

@davidjlaietta
11 years ago

inclusion of $term_template argument

#1 @SergeyBiryukov
11 years ago

  • Description modified (diff)

#2 @johnbillion
11 years ago

  • Version changed from trunk to 2.5

#3 @johnbillion
11 years ago

  • Keywords has-patch needs-testing added

#4 @boonebgorges
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 @wildworks
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.

https://github.com/WordPress/gutenberg/issues/69250

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

#7 @poena
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 @SirLouen
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

  1. ✅ Issue resolved with patch.
  2. ✅ 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

  1. ❌ 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 @wildworks
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>`
);
Note: See TracTickets for help on using tickets.