• Resolved juliajune

    (@juliajune)


    I want to display only the popular posts (not pages) tags on a single page.
    I want to show a preview of the post with its css class or id.

    How can I do this using a filter wpp_custom_html
    Here only the title. How can I show preview?

    $output .= "<h2 class=\"entry-title\"><a href=\"" . get_the_permalink( $popular->id ) . "\" title=\"" . esc_attr( $popular->title ) . "\">" . $popular->title . "</a></h2>";

    Or how can I do it with
    Settings->WordPress Popular Posts->Parameters->post_html
    It’s code view preview without class. And size inside tags, not in css class.

    <?php wpp_get_mostpopular( 'thumbnail_width=30&thumbnail_height=30' ); ?>

    https://www.ads-software.com/plugins/wordpress-popular-posts/

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

    (@hcabrera)

    Hi there!

    I’m sorry, I’m afraid I don’t understand. What do you mean with “preview”? What are you trying to do?

    Thread Starter juliajune

    (@juliajune)

    Sorry, post preview is featured image in post see screenshoot https://prntscr.com/9yn1ef

    By default with this code

    <?php wpp_get_mostpopular('thumbnail_width=30&thumbnail_height=30&post_type="post"'); ?>

    Popular posts look like this https://prntscr.com/9yn9gw
    It’s test site. Height and weight inside tag.
    Popular post image has class by default .wpp-thumbnail .wpp_cached_thumb .wpp_featured

    My life site this
    I want to look so popular posts https://prntscr.com/9yn8qg

    How can I include my custom class for image

    .attachment-related .wp-post-image{
     ....
     width:235px;
     height: 190px;
     ....
    }

    to popular posts.

    OR How can I do this with a filter wpp_custom_html?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Ah, I see what you meant now. Thanks for explaining!

    Try adding the following code at the end of your theme’s functions.php file:

    function add_custom_class_to_wpp_img( $img_tag ){
    
        $dom = new DOMDocument();
        $dom->loadHTML( $img_tag );
        $dom->preserveWhiteSpace = false;
    
        $images = $dom->getElementsByTagName('img');
    
        foreach( $images as $image ) {
    
            // the existing classes already on the image
            $existing_classes = $image->getAttribute( 'class' );
    
            // the classes we're adding
            $new_classes = ' attachment-related wp-post-image';
    
            // the existing classes plus the new class
            $class_names_to_add = $existing_classes . $new_classes;
    
            // set class attribute
            $image->setAttribute( 'class', $class_names_to_add );
        }
    
        $img_tag = $dom->saveHTML();
    
        return $img_tag;
    
    }
    add_filter( 'wpp_render_image', 'add_custom_class_to_wpp_img' );

    I didn’t test this, but I believe it should work. Give it a try and let me know how it goes, alright?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get to the preview in tag?’ is closed to new replies.