• Resolved Peter Smits

    (@psmits1567)


    Hi

    I am a happy user of Post Grid, but have a problem with images not shown
    My posts and pages are build with Site Origin Builder
    If an image is within a widget then it is not shown in the Grid.
    If the image is within a text block then it is shown in the Grid.
    I have investigated the behavior and found the reason for it.
    Site Builder Origin puts special characters into the page aroung images
    Those characters need to be removed before Post Grid can find the image
    So I altered the code in \includes\function.php
    // Start modification Peter Smits 28-11-2019
    //$post_content = $post->post_content;
    $post_content = htmlspecialchars_decode($post->post_content); // Special characters are not needed !!
    $first_img = ”;
    ob_start();
    ob_end_clean();
    $output = str_replace( array( ‘\/’ ), “\\” ,$post_content); //filter the extra slashes out placed by Site Origin Builder
    $output = str_replace( array( ‘src=\\’ ), ‘src=’,$output); // filter the extra slashes out placed by Site Origin Builder
    $output = preg_match_all(‘/<img.+?src=[\'”]([^\'”]+)[\'”].*>/i’, $output, $matches);
    if(!empty($matches[1][0])){
    $first_img = $matches[1][0];
    // Remove the extra slash at the end if present
    if ($first_img[strlen($first_img) – 1] == ‘\\’){
    $first_img=substr($first_img,0, -1) ;
    }
    // End modification Peter Smits 28-11-2019

    After that I get my images within the grid.
    This code is not perfect it could possibly be improved
    But I would very much like this change within the next official release
    Regards,
    Peter

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author PickPlugins

    (@pickplugins)

    Thanks for the idea,

    i will try and let you know the update.

    Regards

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    Thanks for checking my change
    I have improved it further to not destroy the functionality
    So now a check is done to see if the SiteOrigin builder is active
    Below the changes I made, after it appeard that there was an image missing
    I also added comments to make it better to understand
    It still will need improvement if it can be done better !

    $post = get_post($item_post_id);
    /** $post_content = $post->post_content; */
    $post_content = htmlspecialchars_decode($post->post_content,ENT_QUOTES);
    $first_img = ”;
    ob_start();
    ob_end_clean();

    if ( class_exists( ‘SiteOrigin_Widgets_Bundle’ ) ){
    $output = str_replace( array( ‘\/’ ), “\\” ,$post_content); // SiteOrigin adds \/ combinations
    $output = str_replace( array( ‘src=\\’ ), ‘src=’,$output); // SiteOrigin adds \\
    $output = str_replace( array( ‘”url”:’ ), ‘ <img src=’,$output); //SiteOrigin does change the src to url
    $output = str_replace( array( ‘<img src="’ ), ‘<img src=”‘,$output); //SiteOrigin does add &&lt and &quot combinations which are not removed
    $output = str_replace( array( ‘"”‘ ), ‘”‘,$output); // Remove this quot combination
    $output = str_replace( array( ‘"’ ), ”,$output); // Remove this quot combination

    /** search for post containing SiteOrigin image */
    $findme='”image”:’;
    $start= strpos($post_content, $findme);
    $findme = ‘,”image_fallback”‘;
    $end = strpos($post_content, $findme);
    $lengte= $end-$start;
    $search=(substr($post_content,$start,$lengte));
    /** error_log(‘Gevonden:’ .$search); */
    if ($search !=””){
    /** split the text */
    $stringParts = explode(“:”, $search);
    $firstPart = $stringParts[0];
    /** copy the post_id */
    $ImagePost = $stringParts[1];
    /** error_log(“postNo:” .$ImagePost); */
    $getimage=wp_get_attachment_image($ImagePost );

    if ($getimage !=””){
    $output = $getimage ;
    }
    }
    }
    else {
    /** no SiteOrigin image so get the matches */
    $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post_content, $matches);

    }

    $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*?>/i’, $output, $matches);
    if ($output = ‘0’){
    $output = preg_match_all(‘/?/i’, $output, $matches);
    }

    if(!empty($matches[1][0])){
    $first_img = $matches[1][0];
    $last_char = $first_img[strlen($first_img) – 1]; // Check to see if a slash is at the end of the line
    if ($last_char == ‘\\’){
    $first_img=substr($first_img, 0, -1);
    }
    }

    Thanks for letting me know
    Peter

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    I had to make another change to the functions.php
    The images where scaled from 150×150 px, which causes the pictures to not show properly.
    So I altered the following
    $getimage=wp_get_attachment_image($ImagePost);
    Into
    $getimage=wp_get_attachment_image($ImagePost,$size = ‘medium’ );

    Now it takes the medium format as base to show the image.
    A further improvement would be to take the setting from the widget containing the image. Because that is where the size is set.
    Regards,
    Peter

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    I noticed an update for Post Grid, installed it and found out that my request was not implemented. I would be very happy if you could implement my proposal.
    Because I probably am not the only one using SiteOrigin SiteBuilder

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    I noticed again an update for Post Grid, installed it and found out that my request was not implemented. I would be very happy if you could implement my proposal.
    Because I probably am not the only one using SiteOrigin SiteBuilder
    When are you going to implement this feature ?
    It is important for me, so I would be very happy if it is added
    Now I have to implement it myself after every update

    Plugin Author PickPlugins

    (@pickplugins)

    Hi, sorry to see we missed it, could you please share the code in https://gist.github.com/

    We have redesigned the layout editor, not it’s much easier to create new element for layout, i would like to suggest you create your own element and add it via layout editor, let me finish writing documentation on how to create elements for post grid layout.

    View post on imgur.com

    Regards

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    I created a new gist:b948b19734d3b9d89f8791bd1b4a5d4f
    I hope this is the proper way to share the code
    The change is made within \imcludes\function.php
    Regards,
    Peter

    Plugin Author PickPlugins

    (@pickplugins)

    Hi, i just try SIteOrigin and your code, i have added new media source “SiteOrigin first image” please see the screenshot,

    View post on imgur.com

    Please try latest version and let me know the rsult.
    Regards

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    Installed the new version, now I do get the first image of the posts
    I have set the first image to be SiteOrigin Builder
    And that is now shown, but not for all posts
    I need to check why these posts do not show the first image
    With the previous version that did work with my code.
    I will come back on this issue tomorrow
    But now I can use the plugin again!
    Thanks for your quick support !
    Peter

    Plugin Author PickPlugins

    (@pickplugins)

    Please make sure you place the top “SiteOrigin first image” to make top priority.

    Regards

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    I did put “SiteOrigin first image” at the top within each grid
    And most of the time it works, but sometimes it does not work
    It might have something to do with the name of the image
    I need to check that tomorrow, as I need to add debug statement
    Thanks for your reply
    Peter

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    Finally I got the time to sort my problem out
    It was indeed the fact that in one of my grids the “SiteOrigin first image” was not set.
    So this issue can be closed as the plugin does now what I expected it to do
    Many thanks for your support!
    Peter

    Plugin Author PickPlugins

    (@pickplugins)

    Glad to see you found the issue and resolved.

    If you love our plugin and support please help us by providing your feedback and five-star reviews here https://www.ads-software.com/support/plugin/post-grid/reviews/
    Regards

    Thread Starter Peter Smits

    (@psmits1567)

    Hi

    Yes I love the new version, so I gave you a five-star review
    Continue the good job!
    Peter

    Plugin Author PickPlugins

    (@pickplugins)

    Glad to see you love our plugin and thanks for your help regarding SiteOrigin.

    Regards

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Post Grid does not show images when using Site Builder to create the post with’ is closed to new replies.