Problem to add a css class in get_tag_more_links: only first element is classed
-
Hi,
I installed this interesting plugin and I made some improvements like adding a css class to “more tag link” to highlight current_tag.
I edited get_tag_more_links in this way but strangely it only highlights first tag elementpublic static function get_tag_more_links( $tags, $prefix = 'More posts: ' ) { global $wp_query; $tag_array = array(); $output = ''; if ($tags == '') { // if tags is empty then take from current posts if (is_single()) { $tag_array = wp_get_post_tags($wp_query->post->ID); } } else { $tag_array = explode(",", $tags); } if (count($tag_array) > 0) { # ADDED CODE //$current_tag = single_tag_title("", false); $current_tag =get_query_var('tag'); //$output = '<p>' . $prefix; $output = '<ul class = "posts-by-tag-list">'; foreach ($tag_array as $tag) { $tag_name = $tag; if (is_object($tag)) { $tag_name = $tag->name; } $class = 'class="posts-by-tag-item"'; if( $tag_name == $current_tag ) $class = 'class="posts-by-tag-item current_tag_item"'; $output .= '<li ' .$class. '>'; $output .= self::get_tag_more_link( $tag_name ); $output .= '</li>'; } //$output .= '</p>'; $output .= '</ul>'; } return $output; }
I have 2 tags and only first tag is highlighted when I click on it.
Why?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Problem to add a css class in get_tag_more_links: only first element is classed’ is closed to new replies.