Changeset 30209
- Timestamp:
- 11/03/2014 06:48:42 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r30205 r30209 4132 4132 * display the taxonomies for a specific post. 4133 4133 * 4134 * The available defaults are:4135 * 'post' : default is 0. The post ID to get taxonomies of.4136 * 'before' : default is empty string. Display before taxonomies list.4137 * 'sep' : default is empty string. Separate every taxonomy with value in this.4138 * 'after' : default is empty string. Display this after the taxonomies list.4139 * 'template' : The template to use for displaying the taxonomy terms.4140 *4141 4134 * @since 2.5.0 4142 4135 * 4143 * @param array $args Override the defaults. 4136 * @param array $args { 4137 * Arguments about which post to use and how to format the output. 4138 * 4139 * @type int|WP_Post $post Post ID or object to get taxonomies of. Default current post. 4140 * @type string $before Displays before the taxonomies. Default empty string. 4141 * @type string $sep Separates each taxonomy. Default is a space. 4142 * @type string $after Displays after the taxonomies. Default empty string. 4143 * @type string $template Template for displaying a taxonomy label and list of 4144 * terms. Default is "Label: Terms." 4145 * @type string $term_template Template for displaying a single term in the list. 4146 * Default is the term name linked to its archive. 4147 * } 4144 4148 */ 4145 4149 function the_taxonomies( $args = array() ) { … … 4149 4153 'sep' => ' ', 4150 4154 'after' => '', 4151 /* translators: %s: taxonomy label, %l: list of term links */ 4152 'template' => __( '%s: %l.' ) 4155 /* translators: %s: taxonomy label, %l: list of terms formatted as per $term_template */ 4156 'template' => __( '%s: %l.' ), 4157 /* translators: %1$s: term link, %2$s: term name */ 4158 'term_template' => '<a href="%1$s">%2$s</a>', 4153 4159 ); 4154 4160 … … 4174 4180 4175 4181 $args = wp_parse_args( $args, array( 4176 /* translators: %s: taxonomy label, %l: list of term links*/4182 /* translators: %s: taxonomy label, %l: list of terms formatted as per $term_template */ 4177 4183 'template' => __( '%s: %l.' ), 4184 /* translators: %1$s: term link, %2$s: term name */ 4185 'term_template' => '<a href="%1$s">%2$s</a>', 4178 4186 ) ); 4179 4187 … … 4195 4203 $t['template'] = $args['template']; 4196 4204 } 4205 if ( empty( $t['term_template'] ) ) { 4206 $t['term_template'] = $args['term_template']; 4207 } 4197 4208 4198 4209 $terms = get_object_term_cache( $post->ID, $taxonomy ); … … 4203 4214 4204 4215 foreach ( $terms as $term ) { 4205 $links[] = "<a href='" . esc_attr( get_term_link( $term ) ) . "'>$term->name</a>";4216 $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name ); 4206 4217 } 4207 4218 if ( $links ) { -
trunk/tests/phpunit/tests/taxonomy.php
r30141 r30209 50 50 } 51 51 52 /** 53 * @group 27238 54 */ 55 public function test_get_the_taxonomies_term_template() { 56 $post_id = $this->factory->post->create(); 57 58 $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '%2$s' ) ); 59 $this->assertEquals( 'Categories: Uncategorized.', $taxes['category'] ); 60 61 $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ); 62 $link = get_category_link( 1 ); 63 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $taxes['category'] ); 64 } 65 52 66 function test_the_taxonomies() { 53 67 $post_id = $this->factory->post->create(); … … 58 72 59 73 $link = get_category_link( 1 ); 60 $expected = "Categories: <a href='$link'>Uncategorized</a>.";74 $expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.'; 61 75 $this->assertEquals( $expected, $output ); 76 } 77 78 /** 79 * @group 27238 80 */ 81 function test_the_taxonomies_term_template() { 82 $post_id = $this->factory->post->create(); 83 84 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '%2$s' ) ) ); 85 $this->assertEquals( 'Categories: Uncategorized.', $output ); 86 87 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ) ); 88 $link = get_category_link( 1 ); 89 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $output ); 62 90 } 63 91
Note: See TracChangeset
for help on using the changeset viewer.