• Resolved toplez

    (@toplez)


    hello,
    thanks for plugins, like title said it’s possible add active class on current popular posts list?

    thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    The widget automatically adds a class called current to the currently-in-view post / page / ctp.

    Thread Starter toplez

    (@toplez)

    hi,
    thanks for reply, but i using wpp_get_mostpopular( $args );

    Plugin Author Hector Cabrera

    (@hcabrera)

    It’s been a while since I checked that part of the code but I think that only the WPP widget has this functionality. I’ll recheck and get back to you later with suggestions if that’s the case.

    Thread Starter toplez

    (@toplez)

    ok thanks

    Plugin Author Hector Cabrera

    (@hcabrera)

    Well, as mentioned above only the widget has the built-in ability to add a custom CSS class (called current) to a post if we’re viewing it at the moment. Nor the shortcode nor the wpp_get_mostpopular() template tag have this feature.

    A way to achieve this would be by using WPP’s filter hooks in conjunction with WordPress’ get_queried_object_id() function.

    Here’s a quick example using the wpp_post filter hook:

    function my_custom_wpp_html_markup( $original_post_html, $post_object, $instance ){
    
        // Get current post / page ID
        $post_id = ( is_single() || is_page() ) ? get_queried_object_id() : null;
    
        $output = '<li class="' . ( $post_id && $post_id == $post_object->id ? "active" : "" ) . '"><a href="' . get_permalink( $post_object->id ) . '">' . $post_object->title . '</a></li>';
    
        return $output;
    
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘add active class on current popular posts list’ is closed to new replies.