WordPress.org

Ready to get started?Download WordPress

Forums

CSV Importer
Post Thumbnail (26 posts)

  1. Jafet Mejia
    Member
    Posted 3 years ago #

    Hi;

    Is there a way to create a column in the CSV file to setup post thumbnails for the posts or pages? I use this feature to show a preview image in a catalogue site. Thanks

  2. dvkob
    Member
    Plugin Author

    Posted 3 years ago #

    jft.id: Post thumbnails are on my todo list. Am I correct in assuming that you would upload these thumbnail images first and then put their URLs in the thumbnail column?

  3. Jafet Mejia
    Member
    Posted 3 years ago #

    You are in the right assume, I'll first upload the images and then I'll put the URL's in the respective column.

    In fact is what I've done with the images in the content area. So this feature it will take you long?

    Thanks for answering :)

  4. dvkob
    Member
    Plugin Author

    Posted 3 years ago #

    jft.id: The actual coding shouldn't take more than an hour. Finding the time to actually sit down and code is the tricky part. I'll try to do it this weekend, but I won't make any promises.

  5. hilmon
    Member
    Posted 3 years ago #

    Hi,

    Firstly thanks for the great plug-in .... it's going to save me so much time on a catalog site I'm building .....

    I've the same request as jft.id ... I have hunders of products to input and to be able to link to uploaded images would be brilliant!!...

    ..... but eh.... no pressure :-) ... ha ha!

  6. bazonline
    Member
    Posted 3 years ago #

    dvkob: any progressing adding this feature? you will be a lifesaver...

  7. hilmon
    Member
    Posted 3 years ago #

    @bazonline... I spent a full day attaching 500 images to custom posts I had imported with CSV Imported....

    It was hell .... Even filling in the image titles etc.... HELL!!!!!

    A task I never want to repeat but unfortunately may have to in a few weeks.... :-/

    I've been following this thread in hope!!!

  8. bazonline
    Member
    Posted 3 years ago #

    try 1800 posts with 3 images per post.....groan - there must be a way

  9. hilmon
    Member
    Posted 3 years ago #

    Oh WOW!!! Ouch!.....

    I did use a premium theme a while ago http://templatic.com/ecommerce-themes/emporium that had this feature on its CSV importer... I had a look at the import script but it was a little beyond my limited php knowledge...

    But I'll have another look at it and post anything I think might be useful...

  10. bazonline
    Member
    Posted 3 years ago #

    Thanks Hilmon that would be great

  11. hilmon
    Member
    Posted 3 years ago #

    Ok here it is .... It obviously handles the full CSV import (with upto 6 additional images) ....

    <?php
    global $wpdb,$upload_folder_path;
    if($_POST)
    {
    	if($_FILES['bulk_upload_csv']['name']!='' && $_FILES['bulk_upload_csv']['error']=='0')
    	{
    		$filename = $_FILES['bulk_upload_csv']['name'];
    		$filenamearr = explode('.',$filename);
    		$extensionarr = array('csv','CSV');
    		if(in_array($filenamearr[count($filenamearr)-1],$extensionarr))
    		{
    			$destination_path = ABSPATH . $upload_folder_path."csv/";
    			$dest_arr = explode('/',$upload_folder_path."csv");
    			$root_pth = ABSPATH;
    			for($i=0;$i<count($dest_arr);$i++)
    			{
    				$root_pth .= $dest_arr[$i].'/';
    				if (!file_exists($root_pth))
    				{
    					mkdir($root_pth, 0777);
    				}
    			}
    
    			$target_path = $destination_path . $filename;
    			$csv_target_path = $target_path;
    
    			if(@move_uploaded_file($_FILES['bulk_upload_csv']['tmp_name'], $target_path))
    			{
    				$fd = fopen ($target_path, "rt");
    
    ////////////////////////////post image directory start//////////
    				global $General;
    				$imagecustomkeyarray = array('productimage','productimage1','productimage2','productimage3','productimage4','productimage5','productimage6','digital_product'); // custom images and digital product html key names
    				$imagepath = $General->get_product_imagepath();
    				if($imagepath == ''){$imagepath = 'products_img';}
    				$destination_path = ABSPATH . "$upload_folder_path".$imagepath."/";
    
    				if (!file_exists($destination_path))
    				{
    					$imagepatharr = explode('/',$imagepath);
    					$upload_path = ABSPATH . "$upload_folder_path";
    					if (!file_exists($upload_path))
    					{
    						mkdir($upload_path, 0777);
    					}
    					for($i=0;$i<count($imagepatharr);$i++)
    					{
    					  if($imagepatharr[$i])
    					  {
    						  $year_path = ABSPATH . "$upload_folder_path".$imagepatharr[$i]."/";
    						  if (!file_exists($year_path)){
    							  mkdir($year_path, 0777);
    						  }
    						  mkdir($destination_path, 0777);
    						}
    					}
    				}
    				$target_path = $destination_path . $name;
    				$image_user_path = get_option( 'siteurl' ) ."/$upload_folder_path".$imagepath."/";
    ////////////////////////////post image directory end//////////
    
    ///////////post digital product start////////////
    				$digital_product_path = $General->get_digital_productpath();
    				if($digital_product_path == '')
    				{
    					$digital_product_path = 'digital_products';
    				}
    				$digital_destination_path = ABSPATH . "$upload_folder_path".$digital_product_path."/";
    
    				$imagepatharr = array();
    				if (!file_exists($digital_destination_path)){
    				  $imagepatharr = explode('/',$digital_product_path);
    				   $upload_path = ABSPATH . "$upload_folder_path";
    				  if (!file_exists($upload_path)){
    					mkdir($upload_path, 0777);
    				  }
    				  for($i=0;$i<count($imagepatharr);$i++)
    				  {
    					  if($imagepatharr[$i])
    					  {
    						  $year_path = ABSPATH . "$upload_folder_path".$imagepatharr[$i]."/";
    						  if (!file_exists($year_path)){
    							  mkdir($year_path, 0777);
    						  }
    						  mkdir($digital_product_path, 0777);
    						}
    				  }
    			   }
    				$digital_target_path = $digital_destination_path . $name;
    				$digital_user_path = get_option( 'siteurl' ) ."/$upload_folder_path".$digital_product_path."/".$name;
    /////////////////post digital product end////////
    
    				$taxonomysql = "select term_taxonomy_id,term_id from $wpdb->term_taxonomy where taxonomy='category'";
    				$taxonomyres = $wpdb->get_results($taxonomysql);
    				$term_taxonomy_array = array();
    				foreach($taxonomyres as $taxonomyObj)
    				{
    					$term_taxonomy_array[$taxonomyObj->term_id] = $taxonomyObj->term_taxonomy_id;
    				}
    				$rowcount = 0;
    				$customKeyarray = array();
    				while (!feof ($fd))
    				{
    					$buffer = fgetcsv($fd, 4096);
    					if($rowcount == 0)
    					{
    						for($k=3;$k<count($buffer);$k++)
    						{
    							$customKeyarray[$k] = $buffer[$k];
    						}
    					}else
    					{
    						$post_title = addslashes($buffer[0]);
    						$post_desc = addslashes($buffer[1]);
    						$post_cat_arr = explode(',',$buffer[2]); // comma seperated category name
    
    						if($post_title!='')
    						{
    							//////////////////////////////////////////////////////////
    							$post_info_arr = array();
    							$catids_arr = array();
    							$my_post = array();
    							if($post_cat_arr)
    							{
    								for($c=0;$c<count($post_cat_arr);$c++)
    								{
    									$catids_arr[] = get_cat_ID($post_cat_arr[$c]);
    								}
    							}else
    							{
    								$catids_arr[] = 1;
    							}
    							$my_post['post_title'] = $post_title;
    							$my_post['post_content'] = $post_desc;
    							if($post_info_arr['post_author'])
    							{
    								$my_post['post_author'] = $post_info_arr['post_author'];
    							}else
    							{
    								$my_post['post_author'] = 1;
    							}
    							$my_post['post_status'] = 'publish';
    							$my_post['post_category'] = $catids_arr;
    							//$my_post['tags_input'] = $post_info_arr['post_tags'];
    
    							$last_postid = wp_insert_post( $my_post );
    							$customArr = array();
    							for($c=3;$c<count($buffer);$c++)
    							{
    								if(in_array($customKeyarray[$c],$imagecustomkeyarray))
    								{
    									if(trim($buffer[$c])!='')
    									{
    										if(trim($buffer[$c]) == 'digital_product')
    										{
    											$customArr[$customKeyarray[$c]] = $digital_user_path.addslashes($buffer[$c]);
    										}else
    										{
    											$customArr[$customKeyarray[$c]] = $image_user_path.addslashes($buffer[$c]);
    										}
    									}
    								}else
    								{
    									$customArr[$customKeyarray[$c]] = addslashes($buffer[$c]);
    								}
    							}
    							$customArr['posttype'] = 'product';
    							if($customArr)
    							{
    								update_post_meta($last_postid, 'key', $customArr);
    							}
    
    							//////////////////////////////////////////////////////////
    						}
    					}
    				$rowcount++;
    				}
    
    				echo '<br /><div id="message" class="updated below-h2">';
    				echo __("<br><br>csv uploaded successfully");
    				$rowcount = $rowcount-2;
    				echo __("<br><br>Total of $rowcount records inserted</b>");
    				echo __(sprintf("<br><br>Upload images to %s folder.</b>",$destination_path));
    				echo '<br /><br /><br /></div>';
    				@unlink($csv_target_path);
    			}
    			else
    			{
    				$msg = "muerror";
    			}
    		}
    	}else
    	{
    		$msg = "ferror";
    	}
    }
    ?>
    
    <form action="<?php echo get_option('siteurl')?>/wp-admin/admin.php?page=bulkupload" method="post" name="bukl_upload_frm" enctype="multipart/form-data">
      <style>
    h2 { color:#464646;font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;
    font-size:24px;
    font-size-adjust:none;
    font-stretch:normal;
    font-style:italic;
    font-variant:normal;
    font-weight:normal;
    line-height:35px;
    margin:0;
    padding:14px 15px 3px 0;
    text-shadow:0 1px 0 #FFFFFF;  }
    </style>
      <h2><?php _e('Bulk Upload'); ?></h2>
      <?php if($_REQUEST['msg']=='exist'){?>
      <div class="updated fade below-h2" id="message" style="background-color: rgb(255, 251, 204);" >
        <p><?php _e('Uploaded successully.'); ?></p>
      </div>
      <?php }?>
      <table width="75%" cellpadding="3" cellspacing="3" class="widefat post fixed" >
        <tr>
          <td width="14%"><?php _e('Select CSV file'); ?></td>
          <td width="86%">:
            <input type="file" name="bulk_upload_csv" id="bulk_upload_csv"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="<?php _e('Submit'); ?>" onClick="return check_frm();" class="button-secondary action" >    </tr>
        <tr>
          <td>&nbsp;</td>
        <td>    </tr>
        <tr>
          <td colspan="2"><?php _e('You can download'); ?> <a href="<?php echo get_option('siteurl')?>/?page=csvdl"><?php _e('sample CSV file'); ?></a>    </td>
        </tr>
      </table>
    </form>
    <script>
    function check_frm()
    {
    	if(document.getElementById('bulk_upload_csv').value == '')
    	{
    		alert("<?php _e('Please select csv file to upload');?>");
    		return false;
    	}
    	return true;
    }
    </script>
  12. bazonline
    Member
    Posted 3 years ago #

    Hilmon, if you pull this off you rock! and if it doesnt you still rock for trying, thankyou for this, will spend some time on it later today

  13. hilmon
    Member
    Posted 3 years ago #

    Ha ha !!! I can see how it's adding the images to an array etc... put can't figure out how it all gets assigned and stored in the database.....

    So its like we've won the cigar..... but no-one has a light :-/

    Here are the csv column names by the way....

    • Post Title
    • Post Content
    • Post Category
    • productimage
    • productimage1
    • productimage2
    • productimage3
    • productimage4
    • productimage5
    • productimage6
    • digital_product
    • price
    • spPrdLstDate
    • specialprice
    • weight
    • istaxable
    • size
    • color
    • affiliate_link

    I'm sure I'm breaking every copyright law under the sun here.... but hey, desperate times call for desperate measures...

  14. James
    Member
    Posted 2 years ago #

    Hi dvkob,
    Any recent developments on uploading featured images?

  15. Fahd Murtaza
    Member
    Posted 2 years ago #

    Hi everyone

    Since this feature is in to-do list and I have already developed my solution for this, would someone be interested to help me with finalizing the general requirement so I can post the solution specific to my needs as a general solution which will work for everyone.

    I already spent hours to get it to work. So wondering if someone who needs it can define what they want to have as feature of the CSV import. I will post my solution here and later on, if possible can be merged into original plugin?

  16. Fahd Murtaza
    Member
    Posted 2 years ago #

    I personally made it work in a way where you upload your images/files to media and then created a column which has the custom field name. So the custom field value in my column is the name of image/ file already uploaded in media manager of wordpress.

    This is how it works. When you upload the CSV, it will get the column name for the custom field and if it matches certain name, the values will be used for attaching the file to the post.

    This works fine and I have been using it for months. I have also kept tabs on recent changes to the plugin and have been merging my own code to the plugin so its always compatible with the recent changes to plugin.

    I can release my code once a general requirements are laid out for attachments to the posts (attachments/featured images etc) that can work for most situations if not all.

    The reason why I am not posting my code right now is my code is very specific to what I need and I will like to post a generic solution which works for all.

  17. hilmon
    Member
    Posted 2 years ago #

    Hi Fahdi,

    That's great news. I've used CSV Import to populate a couple of large catelogue site but then had to manually go and set the Featured image for each product.

    In all cases I use custom post types and custom taxonomies.

    Basically what most people seem to want (going by the posts I've read here on the forum) is to upload all images thru the media library and then reference the image file names in a column in the CSV. If possible it would be great to have the ability to reference multiple images.... a whole gallery of images to attach to a post.

    Is that enough information?

  18. James
    Member
    Posted 2 years ago #

    Being able to connect medial library images to products would certainly be a handy feature. I have worked on a number of affiliate store sites that receive products with image urls. Why force the extra step of uploading hundreds or even thousands of images via the media library?

  19. Fahd Murtaza
    Member
    Posted 2 years ago #

    So you suggest attaching images to posts based on urls and not the actual media library. Can you elaborate your needs based on your comment above. I think this can be done easily.

  20. hilmon
    Member
    Posted 2 years ago #

    The only issue I would have with a URL approach would that I would want to use the 'thumbnail' version of the image in most instances. Altho, having said that I guess that would be dealt with in the page or post template.

    The thing I really couldn't figure out was the code that actually "attaches" an image (in the library or elsewhere) to a post.

    Does WP use the url of the image when attaching an image to a page or post or does the image (in the library) have an id?

    Sorry for the questions but I might as well take this opportunity to get my head around how this works as its been bugging me for months...

  21. James
    Member
    Posted 2 years ago #

    Hi Fahdi,

    What I am wanting to import is an affiliate datafeed. This feed comes with product images hosted on their server and I would like to use them as the product image(s) and like hilmon I would like to have one column designated as the post thumbnail.

  22. milez
    Member
    Posted 2 years ago #

    I agree with James Callaway above. Exact same requirements here.

    fahdi: Release the codezzz! :-)

  23. hilmon
    Member
    Posted 2 years ago #

    I second that !!!! :-)

  24. bazonline
    Member
    Posted 2 years ago #

    Im looking forward to the progress on this one too

  25. skippix
    Member
    Posted 2 years ago #

    I don't know if this will be helpful or not, but I'll toss it out there.

    I needed to build an archive for digital images. The catalog had a hair under 5000 images organized into 300+ collections. Seeing that the csv importer wouldn't handle images, I opted to go with the built-in WordPress importer.

    To get it to work, I reverse engineered an export and then wrote a little program that generated the xml necessary for the import. It handles posts, images, featured images, and tags (and the images are associated with the post via the post_parent field). My program also sorted out my photos into a folder structure that corresponds to my WordPress upload configuration. In the end, I uploaded my images (yes, that took a while), ran the import, and ultimately had my website completely populated.

    So, it is possible to automate a batch population of a WordPress site. I wrote my program in Delphi (the only language I'm fluent in), and I was able to take advantage of a uniform image naming convention that made it easy to keep things organized. I don't know how well my little program will work for others, but I think the idea is fairly simple. If you have the ability to create your csv file, it might not take you much more work to create the appropriate xml file.

    You can see the end result here

  26. spyboy70
    Member
    Posted 2 years ago #

    Featured images need to be in the WordPress database (as far as I've been able to test), there's no way to reference another URL for those.

    I'm just interested in getting the featured image linked up. I can upload them through the WP media importer (now that v3.3 has the drag and drop capability) and then modify my excel file to use the full path (/wp-content/uploads/2011/12/filename1.jpg)

    I'd have to adjust that full path each month for uploads but that's fairly easy in excel (built a table with variables that I change and the other table will produce the full path)

    When will the featured image support be publicly available (or can you send me a version of it to use now?)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic