Introduce 'tag-link-position-x' class to tag cloud links.
The new class describes the cardinal position of a link in the cloud, allowing more fine-grained CSS and JS targeting. Props Mte90, chmac. Fixes #5172. git-svn-id: https://develop.svn.wordpress.org/trunk@35984 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
62abc10870
commit
22b0cb2029
@ -904,7 +904,8 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
|
||||
|
||||
// generate the output links array
|
||||
foreach ( $tags_data as $key => $tag_data ) {
|
||||
$a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $tag_data['class'] ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>";
|
||||
$class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
|
||||
$a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $class ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>";
|
||||
}
|
||||
|
||||
switch ( $args['format'] ) {
|
||||
|
@ -78,7 +78,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
'number' => 1,
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
|
||||
$this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
|
||||
'hide_empty' => false,
|
||||
) ) );
|
||||
@ -94,7 +94,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
'format' => 'array',
|
||||
) );
|
||||
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
|
||||
$this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
|
||||
'hide_empty' => false,
|
||||
) ) );
|
||||
@ -109,7 +109,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
|
||||
$expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n";
|
||||
$expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n";
|
||||
$this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
|
||||
'hide_empty' => false,
|
||||
'format' => 'list',
|
||||
@ -129,10 +129,10 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>";
|
||||
$expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>";
|
||||
$this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
|
||||
'hide_empty' => false,
|
||||
) ) );
|
||||
@ -152,10 +152,10 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
) );
|
||||
|
||||
$expected = "<ul class='wp-tag-cloud'>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>".
|
||||
"<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>".
|
||||
"</li>\n</ul>\n";
|
||||
|
||||
$this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
|
||||
@ -219,6 +219,26 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase {
|
||||
$this->assertContains( "title='2 foo'", $actual[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5172
|
||||
*/
|
||||
public function test_should_include_tag_link_position_class() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$term_ids = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$p = self::factory()->post->create();
|
||||
wp_set_post_terms( $p, $term_ids, 'wptests_tax' );
|
||||
|
||||
$term_objects = get_terms( 'wptests_tax', array(
|
||||
'include' => $term_ids,
|
||||
) );
|
||||
|
||||
$cloud = wp_generate_tag_cloud( $term_objects );
|
||||
preg_match_all( '|tag\-link\-position-([0-9]+)|', $cloud, $matches );
|
||||
|
||||
$this->assertSame( array( 1, 2, 3 ), array_map( 'intval', $matches[1] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method retrieve the created terms.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user