Default featured image for products

Starting a new thread after cstevenson noted this https://premium.wpmudev.org/forums/topic/need-some-help-styling-my-marketplace#post-136076

Hopefully he’ll chime in with some advice here too.

I need way to automatically assign a default featured image across the network, but only to marketpress products. I have a few lazy sellers who haven’t added featured images yet and it makes the marketplace look bad.

Advice and guidance needed.

Thanks!

  • DavidM
    • DEV MAN’s Mascot

    Hi Saunt,

    I mentioned this thread to him in that post, note sure if he’ll catch this in good time. Nonetheless, I actually just remembered this old plugin that seems to do just that.

    http://wordpress.org/extend/plugins/auto-post-thumbnail/

    The thing is, it supports custom post types, like MarketPress Products, but there’s not a way to get it to auto-thumbnail just the products, without perhaps hacking the plugin code.

    However, it does the trick, in general.

    Cheers,

    David

  • Saunt Valerian
    • The Bug Hunter

    Thanks David, I’ll have a look at it this week!

    I’ll see if there is something in the code to toy with and report back with what I find – though a default image for products would be great if it could be added to marketpress core. Its one of those multisite features that would be good to support MP’s multisite options.

  • cstevenson
    • Site Builder, Child of Zeus

    Hi there

    The only plugin that worked for me was “easy add thumbnail.” The others that did a similar job conflicted with the methods I was using to upload images…. It’s a long story but I am uploading images using custom fields that automatically convert the first image to a thumbnail. So now I don’t need the plugin.

  • Saunt Valerian
    • The Bug Hunter

    The recommended plugin didn't work. It was set for instances in which a post already had an image in it. While this is common in blog posts, product postings aren't always getting them so the use for that plugin is limited.

    I did find an older plugin that does work: http://wordpress.org/extend/plugins/default-post-thumbnails/

    I attached a screenshot of it in action. The code for it is fairly straight forward and I was wondering about how it could be updated to support custom post types. However, given the simplicity of the plugin, I'm wondering why something like this couldn't be coded into MarketPress as part of MP's multisite support.

    In thinking about how the default image plugin might be updated for custom post-types, I though that if that could be done, why bother when the use is more limited. I'm asking as a feature request to take the code, update it and integrate it into MP such that the option to pick a default featured image is available on the MP network settings page. Presumably, the image could be loaded into the media library for the main site on the network and then loaded on the subsites when needed and in the marketplace.

    Having a default image sounds like a natural addition to MarketPress as the plugin matures.

  • cstevenson
    • Site Builder, Child of Zeus

    There is a way of using php to convert images into thumbnail images by changing the ID. You would have to write a function to return the information on images in a post, and then pick one of them to be the thumbnail…

    update_post_meta($post->ID, "_thumbnail_id", $attach_id);

  • Saunt Valerian
    • The Bug Hunter

    I can see use cases where that would be useful, but here I’m talking about product pages (product post_types) when lazy sellers neglect to upload a product image. I can get images converted to thumbnail/featured images, but the issue is they don’t always assign something to the product. These are not ordinary posts we are talking about, but products that appear in a global marketplace.

    I’m looking for a method that will target custom post types (products) and force a default image on them unless the user creates one. The plugin I noted above is a good start, but it is 2 years since an update and doesn’t support custom post types.

  • cstevenson
    • Site Builder, Child of Zeus
    <?php
    if ( has_post_thumbnail() )
    the_post_thumbnail( 'single-post-thumbnail' );
    else
    echo '<img src="' . get_bloginfo( 'defaultimagesdirectory' ) . '/default.jpg" alt="title" title="title" />';
    ?>

    something like that should work

    It needs to be put in the post loop and then you put the default image in defaultimagesdirectory.

  • Saunt Valerian
    • The Bug Hunter

    OKay, that’s a good start, but I still need to a way to have it target product post types. I’m thinking now that this is best deployed as a mu-plugin to make it modular and easily deactivated. I don’t know if Aaron has seen this thread yet, but if he adds the funcitonality into MP, I want to be able to easily turn off my changes.

    Your snippet is a good start, but doesn’t target the product post type. I’m sure how todo that anyhow. The functionality that the above plugin is good too since it offers a UI prompt to the seller to encourage them to add a featured image. If the code for the default post thumbnails plugin could hacked with what you have suggested there (there really doesn’t need to be an admin section for a rough cut of this if everything is defined in the code) then the lightweight plugin can be put in as a mu-plugin that automatically adds the default image to products.

    It’s times like this when I wish I knew php….:slight_frown:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.