WordPress.org

Ready to get started?Download WordPress

Forums

eShop
Alternative to using the WordPress Featured Image? (6 posts)

  1. iftomkins
    Member
    Posted 3 years ago #

    I now understand that to get thumbnails to show up in eshop, you must set the featured image through the "Set Featured Image" function for each post. I'm working on finding a way to automate the process of setting a featured image for each post manually. I have many posts being generated automatically by cronjob (with prices, and an image URL), and then the corresponding images are uploaded separately. I'd like to be able to insert the image URL into a custom field, or in the wp_post_meta table in some way, so that wordpress and eshop know that the URL in this field is the featured image that should be used for the thumbnails. The image is hosted on my server, but I'm looking to avoid manually uploading it for each item. Is there any way to do this, you think?

    If not, would it be possible for me to modify eshop so that instead of looking for the thumbnail as the WordPress featured image, it would look to Get The Image (Justin Tadlock's plugin), TimThumb (which is already used by the eStore theme I'm using), or another automatic thumbnail generator? Thanks!

  2. elfin
    Moderator
    Plugin Author

    Posted 3 years ago #

    in 3.1 you would be able to use: set_post_thumbnail to automatically set it.

    But have a look at the function get_the_post_thumbnail and specifically the filter post_thumbnail_html, which might be useful.

  3. iftomkins
    Member
    Posted 2 years ago #

    Hey Rich, thanks for the feedback! Here's what I'm trying to do, and I've tried to modify the eshop-base.php files, etc. I want to replace the calls for the featured thumbnail, everywhere eshop is looking for the post thumbnail, i want it to use this snippet of code instead:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Thumbnail', true);
    ?>

    That will grab the custom field (which has the thumbnail URL) and put it in the Google Base XML. If I could only modify the files correctly! Any tips?

    Thanks!

  4. elfin
    Moderator
    Plugin Author

    Posted 2 years ago #

    eshop-base-feed.php ?

  5. iftomkins
    Member
    Posted 2 years ago #

    Ok, got it! So, here are instructions to add a custom field value to the eShop Google base feed: (I'll be using it to add an image link, and to add a different brand for each item)

    1. Open eshop-base-feed.php.

    2. Up top somewhere, add this code:

    global $wp_query;
    $postid = $wp_query->post->ID;
    $imagelinkcustom = get_post_meta($postid, 'Thumbnail', true);

    It defines the variable $imagelinkcustom from the custom field “Thumbnail”. Replace "Thumbnail" with the name of the custom field you want to grab.

    3. Replace lines 107-111 with this:

    <item>
    	<link>'.eshoprssfilter($baselink).'</link>
    	<title>'.eshoprssfilter($basetitle).'</title>
    	<description>'.eshoprssfilter($basedescription).'</description>
    	<g:id>'.eshoprssfilter($baseid).'</g:id>
    	<g:image_link>'.$imagelinkcustom.'</g:image_link>';

    The key part of the above code is this line:

    <g:image_link>'.$imagelinkalan.'</g:image_link>

    But it’s a little tricky to get the apostrophes right, so you can just paste the whole thing. :)

  6. iftomkins
    Member
    Posted 2 years ago #

    Nevermind! The code doesn't quite work. It does not cycle through all the wordpress posts, it just used the custom field value from the first post. I guess you'd have to do a for each scenario on it? I'm not sure how eshop-base-feed.php loops through the products. Rich, would you have any suggestions? This is what I have now for defining the variables $imagelink and $brand. I guess it's not a constant variable, it needs to be an array of products, but I can't figure out how to insert this whole mess inside the<item> template you've laid out.

    global $wp_query;
    $postid = $wp_query->post->ID;
    $imagelink = get_post_meta($postid, 'Thumbnail', true);
    
    global $wp_query;
    $postid = $wp_query->post->ID;
    $brand = get_post_meta($postid, 'brand', true);

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags