• Resolved Lyk

    (@lyk-1)


    As it has already been explained by one of the developers, the way featured images are set is the following:

    The way the import mechanism works is that it downloads all of the posts. It then runs through those in batches looking for images of the form:

    <img src=”yyy”>
    or
    <img src=”yyy”>

    For each image

    downloads the biggest image size.
    Use big image to re-generate the smaller sizes based on your wordpress settings, it is this step that times out in your case.
    Creates an “attachement” record in the post table.
    updates the html in the post to point at the new images.
    If this is the first image then set it as the “featured” image

    This is very similar to the way the WordPress editor works.

    The bold part can be disabled by commenting out the following lines in the blogger-importer-blog file:

    //if ($imgcount == 0)
                //{
                    //set_post_thumbnail($post_id, $att_id);
                //}

    But in the end this is quite a useful feature.

    The “problem” is that if a post was already starting with an image, this image is set as featured and as a result those posts have the same image showing up twice.

    My question is how can one modify the plugin in such a way that the first image is set as featured, but it removed from the post?

    Thank you!

    https://wordpress.org/plugins/blogger-importer/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Workshopshed

    (@workshopshed)

    Hi Lyk,
    that doubled-up image is a feature of the theme, although I see that’s exactly how the Twenty Thirteen and Fourteen themes work.
    Getting the importer to delete the now redundant image is not straightforward is it currently geared up to just replace the file location not the whole image tag.
    I am making some changes around that area so I’ll have a think about how this might be incorporated but effectively those new themes mean that this feature of the importer is not of use.
    The reason I’ve not spotted this before is that my theme just shows the excerpt rather than the whole post so I get a thumbnail exceprt
    Cheers,
    Andy

    Thread Starter Lyk

    (@lyk-1)

    Hello Andy,

    Yes, it is theme related, but it is quite probable that a theme shows the featured image at the top of each post (probably in some different/special way)

    I was thinking that it might be easy to be done by tweaking the part that:

    updates the html in the post to point at the new images

    So something like:

    if ($imgcount == 0)
    {
        // update the html in the post with nothing, i.e. omit the matched regular expr
        set_post_thumbnail($post_id, $att_id);
    } else {
        // update the html in the post to point at the new images.
    }

    But apparently it is not as simple as it looks.

    I also did some searching for some plugin that just removes the first image from every post, but have not find something yet. This should be simple but I am really new in wordpress 😛 . Such a plugin will do the job right?

    Apart from that, I found this http://setwordpress.com/2011/09/29/how-to-remove-first-image-from-wordpress-posts/
    but for some reason it does not work for me.
    Moreover, -if I got it right- this will not really change the content of the posts and will only change the way they appear (on the fly each time). Which is not very good.

    PS: it also seems that there is a redundant condition in the if(), unless I really miss something?

    Thank you!

    Plugin Author Workshopshed

    (@workshopshed)

    If you combine those two ideas you should have something that works.

    The regular expression used for detecting images is

    <img[^>]*src\=([\”‘`])([^\> ]*?)\\1[^>]*>

    The post content at this point in the code is held in $postcontent

    Thread Starter Lyk

    (@lyk-1)

    I guess you are talking about the code in the functions.php ?

    Yes, maybe I try that as a temp solution for a while..

    Update: I tried with the regex you wrote but it seems to match everything, i.e. all the post is removed apart from the featured image.

    The regex in the link works. I hadn’t notice before because I was checking the homepage. So it works for every post, but the problem still shows up in the homepage.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Featured images’ is closed to new replies.