Viewing 15 replies - 31 through 45 (of 45 total)
  • Thread Starter Amilus

    (@amilusc)

    Hi thanks!
    I will test the code sometime soon and let you know how it goes!

    For the earlier gif thumbnail issue, here’s what I got back from HostGator after several e-mail:

    1. After I explained the problem and included your error message, here’s what they replied first:

    Thank you for contacting HostGator support.
    I will be more than happy to help you with this.
    I have increased the memory limit in PHP on your account.
    Could you please try to see if you are still having issues on this site?
    If you are, could you please provide the exact steps to replicate the problem?

    2. The problem wasn’t solved, I e-mailed them the problem with the error message provided by you again, but however my step to step explanation probably wasn’t good enough for them to reproduce the issue on their side. This is what they replied after the 2nd e-mail:

    Hello,
    
    To get a better understanding of which memory limits you are reaching,
    please provide the steps taken in attempting to generate the thumbnail,
    as well as the original image. ImageMagick is properly functioning,
    however the error being received is due to reaching a memory limit,
    and not due to faults with ImageMagick.

    What I have provided them the step by step to reproduce the problem was:
    1.build a self-hosted wp site using their server
    2. add WPPP plug-in
    3. set a gif file as featured image

    I guess this isn’t what they were asking for. Is there any further information I could provide them to check the gif problem?

    Many thanks!!

    Plugin Author Hector Cabrera

    (@hcabrera)

    You can suggest them to look into this as it might help easing the memory usage issue.

    As for the steps to reproduce the issue, here’s a sample code:

    $some_ID = 1; // Post / page ID
    $thumb_width = 130;
    $thumb_height = 130;
    $path = 'path/to/original-image.gif'; // change this path!
    $path_to_uploads = 'path/to/wp-content/uploads/wordpress-popular-posts'; // change this path!
    $image = wp_get_image_editor( $path );
    
    // valid image, create thumbnail
    if ( !is_wp_error($image) ) {
    	$file_info = pathinfo($path);
    
    	$image->resize($thumb_width, $thumb_height, true);
    	$new_img = $image->save( trailingslashit( $path_to_uploads ) . $some_ID . '-' . $thumb_width . 'x' . $thumb_height . '.' . $file_info['extension'] );
    
    	if ( is_wp_error($new_img) ) {
    		echo $new_img->get_error_message();
    	}
    
    	echo $new_img['file'];
    }
    
    echo $image->get_error_message();
    Thread Starter Amilus

    (@amilusc)

    Hi Hector,

    Thank you!
    I just forwarded the gif thumbnail error informtation to HostGator and hope to hear back from them soon.

    I tested the custom thumbnail and the layout looked perfect, however
    1. The WPML multi-languages doesn’t function with the customised WPPP function code.
    It stays English regardless whichever language I switch to, so I couldn’t test if the excerpt code works well in Japanese and Chinese.

    2.After adding the custom wppp code into my function.php, not only the most popular section on the index but also the wppp widget on the sidebar in my single post page changes to the same layout, too.

    For the moment I simply added the wppp widget to the side bar and it looks like this:
    https://a-unefille.com/zh-hant/2014/12/05/royal-college-of-art-christmas-fete-2/
    (see the sidebar on the right)

    But adding the customised wppp code in function.php’d achieve the perfect layout in index.php but ruin the layout on single post page… Is there a way to solve this?

    Thank you so much for taking so much time on my massive problems…

    Thread Starter Amilus

    (@amilusc)

    P.S. Just noticed another issue that many of my exiting past posts were written in Chinese or Japanese instead of the default language English.

    As I start adding the English version of them, the duplicated wppp problem happens again.

    For the moment I start all new post by making the English post first (even just leave it blank), then the other languages, which should avoid the duplicate wppp problem. But For the exiting non-english posts (quite a lot), as I start to translate them into English, the duplication happens.

    Plugin Author Hector Cabrera

    (@hcabrera)

    This is going to be a lengthy post!

    1. The WPML multi-languages doesn’t function with the customised WPPP function code. It stays English regardless whichever language I switch to, so I couldn’t test if the excerpt code works well in Japanese and Chinese.

    You mean the excerpt? If so, that’s odd. The modification I posted above only checks for the current language before cropping the excerpt, the rest of the code is basically the same.

    2. After adding the custom wppp code into my function.php, not only the most popular section on the index but also the wppp widget on the sidebar in my single post page changes to the same layout, too.

    That is to be expected. The function doesn’t check what page is being displayed, so the same HTML markup is used everywhere. You need to take care of that by yourself. The is_front_page() conditional is what you need:

    function custom_popular( $mostpopular, $instance ){
    
        if ( is_front_page() ) {
    	// Code for popular list on front page goes here
        } else {
    	// Code for popular list everywhere else goes here
        }
    
        return $output;
    
    }
    
    add_filter( 'wpp_custom_html', 'custom_popular', 10, 2 );

    Just noticed another issue that many of my exiting past posts were written in Chinese or Japanese instead of the default language English.

    As I start adding the English version of them, the duplicated wppp problem happens again.

    Yep, that’s what I explained here. Speaking of which, I managed to find a solution for that.

    Instructions:

    1. Put your site into Maintenance mode to prevent visitors from checking your site while you do the merging process (you can use this plugin for that).
    2. Add the missing english translations to your posts / pages. This is so WPP can track the post IDs correctly from now on.
    3. When you’re done with the translations, backup your site’s database. Don’t proceed further until you do.
    4. I created a plugin (called it WPP x WPML, wasn’t feeling very creative hehe) for the sole purpose of merging the visits from two (or more) languages into the default one (english, in your case). This will fix the duplicate posts issue. Download it, install it and don’t leave the Plugins screen. Upon activation, the merging process will start. Again, don’t leave the Plugins screen or the merging process will be interrupted. When it’s done, you’ll get an ugly “completed” message on screen.
    5. Disable the WPP x WPML plugin (you can even delete it afterwards if you want).
    6. Disable the Maintenance mode so your site can go back online.
    Thread Starter Amilus

    (@amilusc)

    Hi Hector,
    Not the excerpt but the language just doesn’t change in wppp after I added the costum_popular into function.php.

    Please see here:
    https://a-unefille.com/ja/
    https://a-unefille.com/zh-hant/

    The language in wppp stays English regardless which language of the site that I’m viewing.

    Thread Starter Amilus

    (@amilusc)

    After adding the is_front_page part now the layout of wppp looks wonderful everywhere!

    But it doesn’t work with multi languages…which is very odd.
    I remember that it did function well in different language when I tested the costum_popular last time, and that’s why I noticed the excerpt length problem in kanji languages.
    I really can’t think of what is causing the problem.

    I will now add the english version to all the exiting posts and test wpp x wpml plug-in and will get back to you once it’s done.
    And again, thank you so much for everything…

    Thread Starter Amilus

    (@amilusc)

    Hi Hector,

    I’ve added the English version to all the exiting posts ( didn’t really have them all translated, but at least to the system now the English version exist and I’ll come back to do the real translation by editing the posts).

    However the same problem with wppp using costom_popular function still exisit, it does not function with wpml language switcher.

    The most popular posts stay in English regardless whichever language I switch to…

    Thread Starter Amilus

    (@amilusc)

    Oh but the gif thumbnail problem being generated by wppp is fixed while using the costum_popular_post function…

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi Amilus!

    Please, post your code here so I can test it.

    Thread Starter Amilus

    (@amilusc)

    Thank you so much!

    Here’s the code in function.php

    function get_excerpt_by_id( $post_id ){
        $the_post = get_post( $post_id ); //Gets post ID
        $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
        $the_excerpt = strip_tags( strip_shortcodes($the_excerpt) ); //Strips tags and images
    
        if ( defined('ICL_LANGUAGE_CODE') && (ICL_LANGUAGE_CODE == 'jp' || ICL_LANGUAGE_CODE == 'cn') ) {
    
            $excerpt_length = 180; //Sets excerpt length by letter count
    
            if ( strlen($the_excerpt) > $excerpt_length ) {
                $the_excerpt = mb_substr( $the_excerpt, 0, $excerpt_length ) . "...";
            }
    
        } else {
    
            $excerpt_length = 35; //Sets excerpt length by word count
            $words = explode( ' ', $the_excerpt, $excerpt_length + 1 );
    
            if ( count($words) > $excerpt_length ) :
                array_pop($words);
                array_push($words, '...');
                $the_excerpt = implode(' ', $words);
            endif;
    
        }
    
        $the_excerpt = '<p>' . $the_excerpt . '</p>';
    
        return $the_excerpt;
    }
    
    function custom_popular( $mostpopular, $instance ){
         if ( is_front_page() ) {
        $counter = 0;
    
        $output = '<ul class="wpp-list">';  
    
        foreach( $mostpopular as $popular ) {
    
            $permalink = get_permalink($popular->id);
            $excerpt = "";
    
            // Different output for the first post: show different thumbnail and post excerpt (summary)
    
            if ( 0 == $counter ) {
    
                $thumbnail = get_the_post_thumbnail( $popular->id, 'popular', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
                $excerpt = " <span class=\"wpp-excerpt\">" . get_excerpt_by_id( $popular->id ) . "</span>";
                $output .= "<div id=\"most-liked-left\"><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li><li>{$excerpt}</li></div>";
    
            }
             else { // Regular output
                $thumbnail = get_the_post_thumbnail( $popular->id, 'square', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
                $output .= "<div id=\"most-liked-side\"><ul><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li><ul></div>";
    
            }
    
            $counter++;
        }
        }
        else  {
        $output = '<ul class="wpp-list">';
        foreach( $mostpopular as $popular){
            $permalink = get_permalink($popular->id);
            $output .="<li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li>";
        }
        }
    
        return $output;
    }
    add_filter( 'wpp_custom_html', 'custom_popular', 10, 2 );

    and in index.php

    <?php wpp_get_mostpopular("range=weekly&limit=4&excerpt_length=150&stats_date=1&post_type='post'&stats_category=1"); ?>

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi Amilus!

    Your code is fine. The problem was that the wpp_custom_html filter receives the raw popular data – that is, posts without translations (people using the filters are supposed to handle everything by themselves hehe).

    Anyways, I just updated it so it works with WPML (your HTML code is quite odd, by the way):

    function get_excerpt_by_id( $post_id ){
    
        $the_post = get_post( $post_id ); //Gets post ID
        $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
        $the_excerpt = strip_tags( strip_shortcodes($the_excerpt) ); //Strips tags and images
    
        if ( defined('ICL_LANGUAGE_CODE') && (ICL_LANGUAGE_CODE == 'jp' || ICL_LANGUAGE_CODE == 'cn') ) {
    
            $excerpt_length = 180; //Sets excerpt length by letter count
    
            if ( strlen($the_excerpt) > $excerpt_length ) {
                $the_excerpt = mb_substr( $the_excerpt, 0, $excerpt_length ) . "...";
            }
    
        } else {
    
            $excerpt_length = 35; //Sets excerpt length by word count
            $words = explode( ' ', $the_excerpt, $excerpt_length + 1 );
    
            if ( count($words) > $excerpt_length ) :
                array_pop($words);
                array_push($words, '...');
                $the_excerpt = implode(' ', $words);
            endif;
    
        }
    
        $the_excerpt = '<p>' . $the_excerpt . '</p>';
    
        return $the_excerpt;
    
    }
    
    function custom_popular( $mostpopular, $instance ){
    
    	$output = '<ul class="wpp-list">';
    
    	// Code for home page
    	if ( is_front_page() ) {
    
    		foreach ( $mostpopular as $popular ) {
    
    			/*
    			 * Get title, permalink, thumbnail, excerpt, etc.
    			 */
    
    			// WPML support
    			if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
    
    				$current_id = icl_object_id( $popular->id, get_post_type( $popular->id ), true, ICL_LANGUAGE_CODE );	
    
    				$title = get_the_title( $current_id );
    				$permalink = get_permalink( $current_id );
    				$thumbnail = get_the_post_thumbnail( $current_id, 'popular', array('alt' => esc_attr($title), 'title' => esc_attr($title), 'class' => 'wpp-thumbnail') );
    				$excerpt = "<span class=\"wpp-excerpt\">" . get_excerpt_by_id( $current_id ) . "</span>";
    
    			}
    			else {
    
    				$title = $popular->title;
    				$permalink = get_permalink( $popular->id );
    				$thumbnail = get_the_post_thumbnail( $popular->id, 'popular', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
    				$excerpt = "<span class=\"wpp-excerpt\">" . get_excerpt_by_id( $popular->id ) . "</span>";
    
    			}
    
    			/*
    			 * Build popular post HTML
    			 */
    
    			// Show bigger thumbnail for the first image
    			if ( 0 == $counter ) {
    				$output .= "<div id=\"most-liked-left\"><li><a href=\"{$permalink}\" title=\"" . esc_attr($title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($title) . "\">{$title}</a></li><li>{$excerpt}</li></div>";
    			} // Regular output
    			else {
    				$output .= "<div id=\"most-liked-side\"><li><a href=\"{$permalink}\" title=\"" . esc_attr($title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($title) . "\">{$title}</a></li></div>";
    			}
    
    			// Increase counter
    			$counter++;
    
    		}
    
    	} // HTML code for the rest of the site
    	else {
    
    		foreach( $mostpopular as $popular){
    			// WPML support
    			if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
    				$current_id = icl_object_id( $popular->id, get_post_type( $popular->id ), true, ICL_LANGUAGE_CODE );
    				$title = get_the_title( $current_id );
    				$permalink = get_permalink( $current_id );
    			}
    			else {
    				$title = $popular->title;
    				$permalink = get_permalink( $popular->id );
    			}
    
    			$output .="<li><a href=\"{$permalink}\" title=\"" . esc_attr($title) . "\">{$title}</a></li>";
    		}
    
    	}
    
    	$output .= '</ul>';
    
        return $output;
    }
    
    add_filter( 'wpp_custom_html', 'custom_popular', 10, 2 );
    Thread Starter Amilus

    (@amilusc)

    Dear Hector,

    Saying thank you to you just isn’t enough to all the time and effort you spent on this issue.
    I feel bad not paying you tuition fee and coding fee as your support for this free plug-in is so much greater than those paid plug-in…

    I really wish that I could tell you finally this time everything is right now (in fact, almost true! The home page popular posts is really perfect now!).

    However, it seems that the custom_popular function just doesn’t effect the wppp sidebar widget anymore.

    And the WPPP widget in the sidebar does not function with WPML now, even if I take out the entire costume_popular function code, WPPP in the sidebar still doesn’t function with WPML.

    The WPPP on the home page works totally fine with WPML though.

    Here’s my final code:

    <?php
    function get_excerpt_by_id( $post_id ){
    
        $the_post = get_post( $post_id ); //Gets post ID
        $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
        $the_excerpt = strip_tags( strip_shortcodes($the_excerpt) ); //Strips tags and images
    
        if ( defined('ICL_LANGUAGE_CODE') && (ICL_LANGUAGE_CODE == 'ja' || ICL_LANGUAGE_CODE == 'zh-hant') ) {
    
            $excerpt_length = 180; //Sets excerpt length by letter count
    
            if ( strlen($the_excerpt) > $excerpt_length ) {
                $the_excerpt = mb_substr( $the_excerpt, 0, $excerpt_length ) . "...";
            }
    
        } else {
    
            $excerpt_length = 35; //Sets excerpt length by word count
            $words = explode( ' ', $the_excerpt, $excerpt_length + 1 );
    
            if ( count($words) > $excerpt_length ) :
                array_pop($words);
                array_push($words, '...');
                $the_excerpt = implode(' ', $words);
            endif;
    
        }
    
        $the_excerpt = '<p>' . $the_excerpt . '</p>';
    
        return $the_excerpt;
    
    }
    function custom_popular( $mostpopular, $instance ){
    
        $output = '<ul class="wpp-list">';  
    
        // Code for home page
        if ( is_front_page() ) {
    
            foreach( $mostpopular as $popular ) {
    
                // WPML support
                if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
    
                    $current_id = icl_object_id( $popular->id, get_post_type( $popular->id ), true, ICL_LANGUAGE_CODE );    
    
                    $title = get_the_title( $current_id );
                    $permalink = get_permalink( $current_id );
                    $thumbnail = get_the_post_thumbnail( $current_id, 'popular', array('alt' => esc_attr($title), 'title' => esc_attr($title), 'class' => 'wpp-thumbnail') );
                    $excerpt = "<span class=\"wpp-excerpt\">" . get_excerpt_by_id( $current_id ) . "</span>";
    
                }
                else {
    
                    $title = $popular->title;
                    $permalink = get_permalink( $popular->id );
                    $thumbnail = get_the_post_thumbnail( $popular->id, 'popular', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
                    $excerpt = "<span class=\"wpp-excerpt\">" . get_excerpt_by_id( $popular->id ) . "</span>";
    
                }
    
                /*
                 * Build popular post HTML
                 */
    
                // Show bigger thumbnail for the first image
                if ( 0 == $counter ) {
                    $thumbnail = get_the_post_thumbnail( $popular->id, 'popular', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
                    $output .= "<div id=\"most-liked-left\"><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li><li>{$excerpt}</li></div>";
    
                }
                else { // Regular output
                $thumbnail = get_the_post_thumbnail( $popular->id, 'square', array('alt' => esc_attr($popular->title), 'title' => esc_attr($popular->title), 'class' => 'wpp-thumbnail') );
                $output .= "<div id=\"most-liked-side\"><ul><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$thumbnail}</a></li><li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li><ul></div>";
    
                }
    
                // Increase counter
                $counter++;
            }
    
        } // HTML code for the rest of the site
        else  {
    
            foreach( $mostpopular as $popular){
                //WPML support
                if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
                    $current_id = icl_object_id( $popular->id, get_post_type( $popular->id ), true, ICL_LANGUAGE_CODE );
                    $title = get_the_title( $current_id );
                    $permalink = get_permalink( $current_id );
                }
                else {
                    $title = $popular->title;
                    $permalink = get_permalink( $popular->id );
                }
    
                $output .="<li><a href=\"{$permalink}\" title=\"" . esc_attr($popular->title) . "\">{$popular->title}</a></li>";
            }
    
        }
    
        $output .= '</ul>';
    
        return $output;
    }
    add_filter( 'wpp_custom_html', 'custom_popular', 10, 2 );
    ?>

    P.S. No longer related to this plug-in but just to keep you posted for the earlier gif thumbnail issue: the same problem happens again with another plug-in(WordPress Related Posts). I am still seeking support from HostGator to solve it. It seems that there is an error in the gif generated and resized by plug-ins.

    P.P.S. I’ve never learned coding systematically, I am a self-learner copy/paste codes from internet. This is my first time building a wp website. And I really don’t know how I could express my appreciation to all the help and things I learned from you…

    Plugin Author Hector Cabrera

    (@hcabrera)

    Don’t worry about it. I also gather experience from this, and it’s a good exercise to keep my coding skills polished. Also, I’m helping you mainly because I see your will to try things by yourself, and that’s also admirable. Keep it up!

    About the code, I’m away from PC now. I’ll take another look into it during this weekend since I’m moving out from my current office to a new one tomorrow (it’s 10 pm now) and I’m pretty sure I won’t be online that much.

    Thread Starter Amilus

    (@amilusc)

    Long time Hector!
    And Happy New Year!

    Well here’s what HostGator told me regarding the gif issue after a long LiveChat with the technical supporter:

    When the plugin uses the wordpress image editor with imagemagick, it uses too much memory which corrupts the gif more than likely due to animation.

    And after switching off the Imagemagick the gif issue was solved.
    Although this issue does not bother me anymore after using the customised code, but just to keep you posted as you might be interested to know.

    As for the WPML WPPP problem, the widget now works great in different languages.
    The only small problem now is the WPPP on the front page – it does link to the correct language posts but the title is not translated.

    Best

Viewing 15 replies - 31 through 45 (of 45 total)
  • The topic ‘Thumbnail URL does not support on multi-language site’ is closed to new replies.