Sort & Delete Images

This is a bit out there, so i’m hoping somebody can suggest a method and assist with coding said method.

What i have is a remotely hosted csv feeding a wordpress site. (remotely hosted so editing csv is not an option)

The csv contains a list of images for each product each image URL sperated by “;” (without quotes)

So i have no problem exploding the images and pulling each in seperately. My problem lies in the following. Each Product has approximately 15 images with 3 different sizes of each. The url’s are represented like so :

[code] (430px x 322px) [/code]

Long and short is that i only want to pull in the 430px x 322px which are all in
is there anyway to either exclude the images based on dimension or based on the URL containing detail/thumbnail folders ?

I hope my question doesn’t sound too stupid and maybe somebody could advise me on various methods.

Thanks for any help.

You can do a for each statement

Then build a new array and remove all the urls that contain thumbnail, something like this might work, where you’re building a new array with all the urls that contain ‘thumbnail’ removed.

[php] $image_list= explode(";", $yourCSV);
foreach($image_list as $image_url){
if (strpos($image_url,‘thumbnail’) === false) {
array_push($clean_image_list, $image_url)

Thank you very much for your reply. I’m fairly certain it is on the right track but now that i understand that php is an option i should probably explain my exact setup in the hope that someone can help me implement this.

So i am using Wordpress and WP All Import, which automatically process my csv and displays all nodes and allows me to map that node to a Wordpress Meta or Custom field. It also allows the use of php functions and wordpress custom functions. The field for images automatically explodes delimited lists of images and adds them to Wordpress post images, so i need help to work out how to assign your suggestion to my field.

I will provide an example of a custom function i have already used just incase i haven’t been clear on how WP All Import works.

So my example is to display Hotel Facilities as a list in my Wordpress Post Content.

My csv shows the facilities like so :

​24 Hour Reception;​Wi-​Fi Available;​Video/​DVD Player;​TV;​Satellite TV;

So i add this to my theme functions :

function generate_list($list){ $html = '<ul>'; if ( "" != $list){ foreach (explode(';', $list) as $li){ $html .= '<li>' . $li . '</li>'; } } $html .= '</ul>'; return $html; }

Then in WP All Import Post Content i add this


So WP All Import knows use the node “facilities” from my csv and then run the custom function “generate_list” to process that node other wise the node would be just shown in its raw form.

It is also possible in WP All Import to simply run full php functions like this example :


So now that i have explained how this plugin works i really hope someone can help me to implement Topcoders example into my setup.

Thank you once again.

Give this is a try…

[php]function generate_list($list){ $html = ‘

    ’; if ( “” != $list){ foreach (explode(’;’, $list) as $li){ if (strpos($li ,‘thumbnail’) === false) {$html .= ‘
  • ’ . $li . ‘
  • ’; }} } $html .= ‘
’; return $html; }[/php]

Thanks again but i think you have missunderstood me, which is down to my lack of knowledge and explanation. The examples i gave you are just examples of how i have made this work for other functions.

WP All Import comes with an existing function to explode a delimited list of images and add them to the necessary tables for Wordpress Post Images.

What i want to do is have a custom function somehow tap into that and simply run part of your initial suggestion to solely remove URLs containing “thumbnail”.

My examples were just to show how WP All Import already can use a custom function prior to running it’s own function …

So if it is some how possible to create just a custom function along the lines of this ??

 function strip_url{ if (strpos($li ,'thumbnail') === false) }

I know this is incorrect but, i’m just trying to reflect that i just want to remove the urls.

I hope i am a little clearer and i am sincerely greatfull for your help !!

Obviously I can’t test this since I don’t use word press, I’m just taking a guess on the information you provided.

Add this to your theme functions

[php]function strip_thumbnail(($list){ if (strpos($li ,‘thumbnail’) === false) { $image_list= explode(";", yourCSV); foreach($image_list as $image_url){ if (strpos($image_url,‘thumbnail’) === false) {array_push($clean_image_list, $image_url) } }return $clean_image_list;}[/php]

Then call this from WP.


Thank you once again for your reply, unfortunately that didn’t work for me as i think it maybe clashes with WP All Imports defaults, however all is not lost.

Thanks to your suggestions i was able to take a slightly different approach. In stead of using the default image seperator in WP All Import i just created a new Custom Field and called it within my template where the Post Images would have been shown.

I then used a very slightly modified version of your second suggestion to create a Custom Function

function generate_img_list($list){ $html = '<ul>'; if ( "" != $list){ foreach (explode(';', $list) as $li){ if (strpos($li ,'thumbnail') === false) {$html .= '<img src="' . $li . '">'; }} } $html .= '</ul>'; return $html; }

I then called it in WP All Import like so [generate_img_list({hotelimages[1]})]

That basically processes the list of images, removes any with “thumbnail” in the URL and then converts them to placed images. Perfect, i’m just going to use a slideshow script to turn the list of images into a slider by simply adding a class to the img src.

The only thing i would like to ask is how to alter the above to exclude a second word “thumbnail” & “detail” …

Thanks again for all your help, i wouldn’t have got here without it !!

Glad you got it working!

Here’s the change you’re looking for.


[php]if (strpos($li ,‘thumbnail’) === false)[/php]


[php]if ((strpos($li ,‘thumbnail’)) || (strpos($li ,‘detail’)) === false)[/php]

Once again thank you !!!

This is what i’ve got now

function generate_img_list($list){ $html = ''; if ( "" != $list){ foreach (explode(';', $list) as $li){ if ((strpos($li ,'thumbnail')) || (strpos($li ,'detail')) === false) {$html .= '<img src="' . $li . '"/>'; }} } $html .= ''; return $html; }

But it is only removing URLs containing ‘detail’ … Urls containing ‘thumbnail’ are not being removed, have i missed something per chance ?

It looks right to me… the only thing I would do is remove the final $html .= ‘’; it does nothing in the end as seen below.

[php]function generate_img_list($list)
$html = ‘’;
if ( “” != $list)
foreach (explode(’;’, $list) as $li)
if ((strpos($li ,‘thumbnail’)) || (strpos($li ,‘detail’)) === false)
$html .= ‘’;
return $html;

Yeh i have been working on the html to apply the images to Nivo Slider, whilst i appreciate the first and final html do nothing, they wouldn’t prohibit the php from functioning correctly would they ?

Can’t get my head around why it will only recognise the second (strpos($li ,'detail')) and totally ignores the first one …

It should recognize both, unless WordPress does something funny… you can try switching the “||” to “or”.

You can also do it with a preg_match function and you won’t have to use an or statement.

Changing to “or” doesn’t make any difference unfortunately, but thanks for your suggestion, i guess Wordpress messes with it somehow.

I’ll take a look at preg-match, but if i’m honest i don’t fully understand php. But i think it’s only fair that i have a stab at it.

Thank you once again for all your help.

Actually got this sorted by changing my direction slightly, instead of excluding keywords i decided it would make more sense to match what i do want instead which is any url containing “gallery”.

[php]function generate_img_list($list)
$html = ‘’;
if ( “” != $list)
foreach (explode(’;’, $list) as $li)
if (strpos($li ,‘gallery’))
$html .= ‘’;
return $html;
} [/php]

Much more straight forward !! Thank you once again for your help !!!

That’s awesome tascam424.

Glad everything worked out for you!

Sponsor our Newsletter | Privacy Policy | Terms of Service