• Resolved tab7x

    (@tab7x)


    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 element

    public 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?

    https://wordpress.org/plugins/posts-by-tag/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sudar Muthu

    (@sudar)

    You have added the class to the <ul> tag.

    Add it to the <li> tag if you want it to appear to all the items.

    Thread Starter tab7x

    (@tab7x)

    The problem is in the
    <li> element: I add a special class current_tag_item only in current tag browsing. The <ul> class is ok

    Plugin Author Sudar Muthu

    (@sudar)

    Sorry, I am not sure I understand what is the issue you are facing.

    Can you post the html that is generated and explain what you expected to happen and what actually happened?

    Plugin Author Sudar Muthu

    (@sudar)

    I am marking this as resolved. Feel free to reopen if you are still facing this issue.

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.