#27238 closed enhancement (fixed)
Add parameters to the_taxonomies() and get_the_taxonomies() to deselect linking
Reported by: | davidjlaietta | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Currently get_the_taxonomies() automatically wrap all taxonomies that they list in anchor tags:
$links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
We would like to have the option to remove these, to display an unlinked list of taxonomies that are applied to a post:
$list[] = $term->name;
The patch that I've attached includes a 'links' parameter to both the_taxonomies() and get_the_taxonomies(), set to true to not affect existing usage of these functions. If the parameter is set to false, only the taxonomies will be returned, and not their links.
Attachments (6)
Change History (20)
#2
@
11 years ago
- Description modified (diff)
- Version changed from trunk to 3.8
Replying to hereswhatidid:
then $taxonomy_list would contain an array of just the term names.
That would print taxonomy names, but not term names. You can, however, use strip_tags()
to get rid of links:
$taxonomies = array_map( 'strip_tags', get_the_taxonomies() ); echo implode( ' ', $taxonomies );
Looks like 27238.diff is made against 3.8 rather than current trunk, so it cannot be applied properly.
@
11 years ago
Made the term_template default value more in line with what the documentation would support.
#3
follow-up:
↓ 4
@
11 years ago
The 'term_template' argument would enable not only limiting what is displayed but adding more custom elements to the output. Here's an example with the term name only wrapped in a span:
$args = array( 'term_template' => '<span>%2$s</span>' ); get_the_taxonomies( null, $args );
and one that would open the category links in a new window:
$args = array( 'term_template' => '<a href="%1$s" target="_blank">%2$s</a>' ); get_the_taxonomies( null, $args );
#4
in reply to:
↑ 3
@
11 years ago
That would work for me, and makes more sense to allow more control over the template than just adding or removing links.
Replying to hereswhatidid:
The 'term_template' argument would enable not only limiting what is displayed but adding more custom elements to the output. Here's an example with the term name only wrapped in a span:
$args = array( 'term_template' => '<span>%2$s</span>' ); get_the_taxonomies( null, $args );and one that would open the category links in a new window:
$args = array( 'term_template' => '<a href="%1$s" target="_blank">%2$s</a>' ); get_the_taxonomies( null, $args );
#5
follow-up:
↓ 6
@
10 years ago
- Keywords needs-unit-tests added
Agreed that 'term_template' is a better, more general approach.
hereswhatidid - Question about the default value. If you're going to use %2$s
for argument swapping, why not use %1$s
for the first value as well?
Would like to see unit tests demonstrating the new functionality, and especially showing that the default output remains the same as it currently is.
#6
in reply to:
↑ 5
@
10 years ago
Replying to boonebgorges:
Agreed that 'term_template' is a better, more general approach.
hereswhatidid - Question about the default value. If you're going to use
%2$s
for argument swapping, why not use%1$s
for the first value as well?
Would like to see unit tests demonstrating the new functionality, and especially showing that the default output remains the same as it currently is.
The first value was just a copy/paste mistake. %1$s
is what should be there.
#8
@
10 years ago
So in looking at 27238.5.patch, it occurs to me that the default arguments are actually defined in the wrong function. They should be defined in get_the_taxonomies()
. Let's handle moving that code to a separate patch after this is taken care of.
For now, let's move the more in-depth argument descriptions for $template
and $term_template
into the main hash notation that was added to the_taxonomies()
and leave the $args
parameter description on get_the_taxonomies()
as-is for the time being.
#9
follow-up:
↓ 10
@
10 years ago
27238.6.patch updates the argument descriptions per DrewAPicture's comment.
This can already be accomplished with the 'template' argument. You would just call the function like so:
then $taxonomy_list would contain an array of just the term labels.