Tag Cloud element - highlight current item

Hello,

Is it possible to have some sort of class added (or better yet, full customisation within the Style of the element) to show the currently viewed element?

For example, using this as a list of blog categories on the blog archive page, when someone clicks on one of the items, I'd expect to see that one highlighted to indicate the currently viewed item.

e.g.

You can view at https://shorturl.at/125Wi


Thanks

Comments

  • Hi,

    Tag cloud is simply a list of links, and clicking them triggers a page reload, which is why there is no built-in way to mark the clicked link. Implementing this requires custom JavaScript code, which is beyond standard support.

    Thanks for understanding!

  • Thanks, might I ask that you consider adding the following to the sc_tag_cloud function within theme-shortcodes.php file?


    Original:

    $output = '<ul class="'.implode(' ', $classes).'">';
                if ( $terms && ! is_wp_error( $terms ) ) {
                    foreach ( $terms as $term ) {
                        $term_link = get_term_link( $term->slug, $category );
                        if( ! is_wp_error( $term_link ) ){
                            $output .= '<li>';
                                $output .= '<a href="' . esc_attr( $term_link ) . '">';
                                    $output .= __( $term->name );
                                $output .= '</a>';
                            $output .= '</li>';
                        }
                    }
                }
     $output .= '</ul>';
    

    Suggestion:


    $output = '<ul class="'.implode(' ', $classes).'">';
    
    //ADDED BELOW
    $queried_object = get_queried_object();
    
    
                if ( $terms && ! is_wp_error( $terms ) ) {
                    foreach ( $terms as $term ) {
                        $term_link = get_term_link( $term->slug, $category );
                        if( ! is_wp_error( $term_link ) ){
    //ADDED BELOW
    if ( isset( $queried_object->term_id ) && $queried_object->term_id === $term->term_id )
        $output .= '<li class="current-term">';
    else
                            $output .= '<li>';
                                $output .= '<a href="' . esc_attr( $term_link ) . '">';
                                    $output .= __( $term->name );
                                $output .= '</a>';
                            $output .= '</li>';
                        }
                    }
                }
    
            $output .= '</ul>';
    


  • We can't modify it in the theme because it may bring issues to existing customers but you can easily overwrite this function on your end in child theme.

  • Noted, thanks.

    Is there, perhaps, an alternative category listing BeTheme element for blog archives for filters to be shown (like there is in the default blog index for the theme)?

  • Sorry but we don't have any alternative at this moment.

  • OK, thanks - I will add it as a feature-request to ensure the archive template is a viable alternative to the default.

Sign In or Register to comment.