Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 27th, 2011, 11:19 AM
k9marketing k9marketing is offline
 
Join Date: Nov 2010
Posts: 33
Default Drip post and Feature Images

I am using a theme which utilizes the featured image functionality in WP. Currently, I have to go in and edit each post to upload and add the featured image to the post. Anyone have an easier way to accomplish this?
  #2  
Old January 27th, 2011, 12:14 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

You should be able to edit your template and access a different custom field. You will need to access the field store_image in order to display a product's image.

Here's more about editing your template and displaying custom field values:

http://codex.wordpress.org/Custom_Fields

Eric
  #3  
Old January 27th, 2011, 07:52 PM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

If it is to show thumbnails on excerpt pages have a look at a plugin called "Thumbnail For Excerpts"... it looks in your post and adds an image (if found) to the excerpt page automatically...
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #4  
Old May 3rd, 2011, 11:24 PM
Reson8 Reson8 is offline
 
Join Date: Jan 2010
Posts: 24
Default

Hi Eric,

Could you give a little bit more info on how to do this. The link to wordpress.org you supplied gives quite a complex solution. I need a featured image for each of my drip posts as well. I presume this is a common request.

Thanks,
  #5  
Old May 4th, 2011, 08:26 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by Reson8 View Post
Could you give a little bit more info on how to do this. The link to wordpress.org you supplied gives quite a complex solution. I need a featured image for each of my drip posts as well. I presume this is a common request.
I'm not quite sure what you need.... The "Featured Image" feature of WP Posts is not related to the custom field value. It's another value and I have no idea how to make the "Featured Image" field pull from a Custom Field value.
  #6  
Old May 4th, 2011, 10:16 PM
Reson8 Reson8 is offline
 
Join Date: Jan 2010
Posts: 24
Default

OK, but do you think (in theory) it's possible? If so I will use the link you provided and try to find a solution.
  #7  
Old May 5th, 2011, 08:36 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

In theory, anything is possible. I'm not trying to be flip about that. But, you might have to write a plugin which accomplishes what you are trying to do or you might have to hack core WP code.

I have never really hacked around with the Featured Image feature so I'm not sure where to start but I guess I would start with googling about it.

Eric
  #8  
Old May 9th, 2011, 08:48 AM
Reson8 Reson8 is offline
 
Join Date: Jan 2010
Posts: 24
Default

Hi Eric,

Here is what I used to fix this up in my site if it's useful for other users. Paste the code below into the functions.php file. The uploads folder needs to be writable (permissions 777) and the hosting server Must Support file_get_content/fopen/fputs:

function postmeta_img_update() {
global $post;
// If Custom Post Meta Field for a Image/Thumnail Exists
if( get_post_meta($post->ID, "store_image", true) ):

// Get Image Location and File Extention
$img = get_post_meta($post->ID, "store_image", true);
$ext = substr(strrchr($img,'.'),1);

// WordPress Upload Directory to Copy to (must be CHMOD to 777)
$uploads = wp_upload_dir();
$copydir = $uploads['path']."/";

// Code to Copy Image to WordPress Upload Directory (Server Must Support file_get_content/fopen/fputs)
$data = file_get_contents($img);
$filetitle = strtolower(str_replace(array(' ', '-', '.', '(', ')', '!', '@', '#', '$', '%', '^', '&', '*', '_', '=', '+'), "-", get_the_title()));
$file = fopen($copydir . "$filetitle-$post->ID.$ext", "w+");
fputs($file, $data);
fclose($file);

// Insert Image to WordPress Media Libraby
$filepath = $uploads['path']."/$filetitle-$post->ID.$ext";

$wp_filetype = wp_check_filetype(basename($filepath), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => get_the_title(),
'post_content' => 'Image for '.get_the_title(),
'post_status' => 'inherit'
);

wp_insert_attachment($attachment, $filepath, $post->ID);

// Get Attachment ID for Post
global $wpdb; $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");

// Attached Image as Featured Thumbnail in Post
update_post_meta($post->ID, "_thumbnail_id", $attachment_id);

// Removes Custom Meta Field Image URL. This stop this function running again for the updated post.
delete_post_meta($post->ID, "image");

endif;

}
add_action('the_post','postmeta_img_update');

Cheers
  #9  
Old May 9th, 2011, 09:26 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Thanks for sharing, Reson8!
  #10  
Old September 3rd, 2011, 07:22 PM
bigcroc bigcroc is offline
 
Join Date: Oct 2009
Posts: 19
Default

Reason8, thanks but isn't there something more simple than this, I'm trying it now but if you look at for example two themes, twentyten 1.1 and pagelines platform, set reading to latest posts, images show in twenty ten but not platform, why I don't know and I think this is thumbnail related.

Furthermore, when using your php in functions, the images are far too big and break the post but getting host to change access now, is there a way of getting DFR images whether external or uploaded to site to work with the vast array of plugins automatically? For instance sliders etc. I just want the images from dripped posts to show up as visual is obviously more appealing.

And Eric, Hello, I do enjoy this product but is there not an easier way to get images to show? I am using the 'special recent posts' plugin and thanks to reason8, images will work in that but is this possibly something you can consider making automatic in DFR please? Ability to make images easily used within a wp theme. If reason8 enables 'featured posts slideshow' to work also then even better as I've spent hours on this tonight.

Thanks
Lee
  #11  
Old September 3rd, 2011, 07:26 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi Lee

You can post feature requests here: http://www.datafeedr.com/forums/forumdisplay.php?f=69

Eric
  #12  
Old September 3rd, 2011, 08:13 PM
bigcroc bigcroc is offline
 
Join Date: Oct 2009
Posts: 19
Default

Reson8, when you say host must accept fopen, do you mean

allow_url_fopen On On

in phpinfo.php as I'm getting some errors and site seems slower (platform theme) functions.php dump
  #13  
Old December 10th, 2012, 08:58 PM
jerseyal jerseyal is offline
 
Join Date: Sep 2012
Posts: 56
Default

Reson8,

Your code does just what you said it does, but unfortunately, it slows down my site to where it take 30 seconds for pages to load. Have you noticed any performance issues after inserting this code? Also, the featured images are very large, and if I click on it in the WP post page, and look in media gallery, there seems to be over 20 of the same image. Don't know if any of this is related...

What do you think?

Al


Quote:
Originally Posted by Reson8 View Post
Hi Eric,

Here is what I used to fix this up in my site if it's useful for other users. Paste the code below into the functions.php file. The uploads folder needs to be writable (permissions 777) and the hosting server Must Support file_get_content/fopen/fputs:

function postmeta_img_update() {
global $post;
// If Custom Post Meta Field for a Image/Thumnail Exists
if( get_post_meta($post->ID, "store_image", true) ):

// Get Image Location and File Extention
$img = get_post_meta($post->ID, "store_image", true);
$ext = substr(strrchr($img,'.'),1);

// WordPress Upload Directory to Copy to (must be CHMOD to 777)
$uploads = wp_upload_dir();
$copydir = $uploads['path']."/";

// Code to Copy Image to WordPress Upload Directory (Server Must Support file_get_content/fopen/fputs)
$data = file_get_contents($img);
$filetitle = strtolower(str_replace(array(' ', '-', '.', '(', ')', '!', '@', '#', '$', '%', '^', '&', '*', '_', '=', '+'), "-", get_the_title()));
$file = fopen($copydir . "$filetitle-$post->ID.$ext", "w+");
fputs($file, $data);
fclose($file);

// Insert Image to WordPress Media Libraby
$filepath = $uploads['path']."/$filetitle-$post->ID.$ext";

$wp_filetype = wp_check_filetype(basename($filepath), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => get_the_title(),
'post_content' => 'Image for '.get_the_title(),
'post_status' => 'inherit'
);

wp_insert_attachment($attachment, $filepath, $post->ID);

// Get Attachment ID for Post
global $wpdb; $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");

// Attached Image as Featured Thumbnail in Post
update_post_meta($post->ID, "_thumbnail_id", $attachment_id);

// Removes Custom Meta Field Image URL. This stop this function running again for the updated post.
delete_post_meta($post->ID, "image");

endif;

}
add_action('the_post','postmeta_img_update');

Cheers
  #14  
Old December 10th, 2012, 09:39 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Here's the updated code which goes in your theme's functions.php file. I've only tested that it works... it has not been tested for security or anything else.

Use at your own risk!

PHP Code:
function postmeta_img_update() {
    
    global 
$post;

    
// If Custom Post Meta Field for a Image/Thumnail Exists
    
if( get_post_meta($post->ID"store_image"true) ) {
    
        
$dfr_featured_image_is_set get_post_meta($post->ID"dfr_featured_image_is_set"true);
        
        if (
$dfr_featured_image_is_set == 'yes') {
            return;
        }

        
// Get Image Location and File Extention
        
$img get_post_meta($post->ID"store_image"true);
        
$ext substr(strrchr($img,'.'),1);

        
// WordPress Upload Directory to Copy to (must be CHMOD to 777)
        
$uploads wp_upload_dir();
        
$copydir $uploads['path']."/";

        
// Code to Copy Image to WordPress Upload Directory (Server Must Support file_get_content/fopen/fputs)
        
$data file_get_contents($img);
        
$filetitle strtolower(str_replace(array(' ''-''.''('')''!''@''#''$''%''^''&''*''_''=''+'), "-"get_the_title()));
        
$file fopen($copydir "$filetitle-$post->ID.$ext""w+");
        
fputs($file$data);
        
fclose($file);

        
// Insert Image to WordPress Media Libraby
        
$filepath $uploads['path']."/$filetitle-$post->ID.$ext";

        
$wp_filetype wp_check_filetype(basename($filepath), null );
        
$attachment = array(
            
'post_mime_type' => $wp_filetype['type'],
            
'post_title' => get_the_title(),
            
'post_content' => 'Image for '.get_the_title(),
            
'post_status' => 'inherit'
        
);

        
wp_insert_attachment($attachment$filepath$post->ID);

        
// Get Attachment ID for Post
        
global $wpdb$attachment_id $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");

        
// Attached Image as Featured Thumbnail in Post
        
update_post_meta($post->ID"_thumbnail_id"$attachment_id);

        
// Removes Custom Meta Field Image URL. This stop this function running again for the updated post.
        
add_post_meta($post->ID"dfr_featured_image_is_set""yes");

    }
}
add_action('the_post','postmeta_img_update'); 
Eric
  #15  
Old December 10th, 2012, 09:56 PM
jerseyal jerseyal is offline
 
Join Date: Sep 2012
Posts: 56
Default

It works! Thank you!
  #16  
Old October 15th, 2013, 03:10 PM
froogly froogly is offline
 
Join Date: Sep 2013
Posts: 5
Default

Hi, do I copy that code anywhere inside my functions.php file? Do I enclose this code with any other code? I really would love for this to work, to get creative with datafeedr, most plugins, use the featured image.

Thank You
  #17  
Old October 15th, 2013, 03:12 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

That code should go at the bottom of your theme's functions.php file. This can sometimes be tricky.

Make sure it appears before the final line that contains ?>

Eric
  #18  
Old October 17th, 2013, 01:54 PM
froogly froogly is offline
 
Join Date: Sep 2013
Posts: 5
Default

Hi Eric, is this what the server needs to be able to do this - allow_url_fopen = On - for some reason, some pictures loaded fine, and some did not load, after I placed the code.

thank you
  #19  
Old October 17th, 2013, 01:58 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

No, that code doesn't require allow_url_fopen... at least I don't see use of that function in the code. That code requires:

file_get_content()
fopen()
fputs()

However, some pictures might not load fine on your site because the merchant has blocked the remote downloading of their images. There's not much you can do about that...

Eric
  #20  
Old October 17th, 2013, 02:52 PM
froogly froogly is offline
 
Join Date: Sep 2013
Posts: 5
Default

Hi Eric thank you for the prompt response, I think that might be the case, is there a way to filter stores, based on remote download capabilities?
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:40 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.