OrganizedFellow Posted September 18, 2013 Share Posted September 18, 2013 I am modifying the Skyscrapers profile for a pretend realty company. It seems well suited to the job + this seems like a superb way to "get to know PW" further. I thought I'd simply replace height with square footage. Floors and year opened will be replaced with number of bedrooms/bathrooms + year built. I haven't started yet A very time consuming part appears to be the part related to replacing all the skyscraper images with my own. What is the easiest way to replace all images in Skyscrapers profile with my own? I'm looking at a sql dump of the project and it looks like there are 71 mentions of '.jpg' under the `field_images` table, data column. But when I do a search for any of these file names (for example: sears1.jpg, westin.jpg, marriott3.jpg) in my actual folder/file structure, they are not found. What would be the simplest way to replace all the images with my own? Link to comment Share on other sites More sharing options...
Craig Posted September 18, 2013 Share Posted September 18, 2013 I think the best way would be to do this with a bit of code. Use a selector to find all the pages with images you want to edit, iterate through them all, remove the existing image, and then just add your own. For example: $pages = wire('pages')->find("template=property"); foreach ($pages as $page) { $page->images->deleteAll(); $page->images->add("http://images.com/image1.jpg"); $page->save(); } I haven't tested that on a site, but you get the idea. You could have that code in a template file, or in a separate PHP file and include ProcessWire - as explained here. 1 Link to comment Share on other sites More sharing options...
kongondo Posted September 18, 2013 Share Posted September 18, 2013 OF, I think you are confusing the Blog Profile and the Skyscrapers profile. Those images are in the latter, not the former . For instance, westin.jpg is here: /site/assets/files/4179 and marriott3.jpg at /site/assets/files/4190 1 Link to comment Share on other sites More sharing options...
OrganizedFellow Posted September 18, 2013 Author Share Posted September 18, 2013 OF, I think you are confusing the Blog Profile and the Skyscrapers profile. Those images are in the latter, not the former . For instance, westin.jpg is here: /site/assets/files/4179 and marriott3.jpg at /site/assets/files/4190 Thank you, my mistake, I should have caught that. I think the best way would be to do this with a bit of code. Use a selector to find all the pages with images you want to edit, iterate through them all, remove the existing image, and then just add your own. For example: $pages = wire('pages')->find("template=property"); foreach ($pages as $page) { $page->images->deleteAll(); $page->images->add("http://images.com/image1.jpg"); $page->save(); } I haven't tested that on a site, but you get the idea. You could have that code in a template file, or in a separate PHP file and include ProcessWire - as explained here. Thanks, I will give that a shot later today. Link to comment Share on other sites More sharing options...
ryan Posted September 22, 2013 Share Posted September 22, 2013 The deleteAll() is actually a queued call that occurs when the page is saved. As a result, you might need to add $page->save() right after the deleteAll() call, just so that it doesn't end up deleting the newly added image too. 2 Link to comment Share on other sites More sharing options...
OrganizedFellow Posted September 23, 2013 Author Share Posted September 23, 2013 The deleteAll() is actually a queued call that occurs when the page is saved. As a result, you might need to add $page->save() right after the deleteAll() call, just so that it doesn't end up deleting the newly added image too. I havent gotten around to it yet Ryan (busy week with the kiddos). Could ya provide me with a code snippet to make this work? Link to comment Share on other sites More sharing options...
arjen Posted September 23, 2013 Share Posted September 23, 2013 I think Ryan means this: $pages = wire('pages')->find("template=property"); foreach ($pages as $page) { $page->images->deleteAll(); $page->save(); $page->images->add("http://images.com/image1.jpg"); $page->save(); } 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now