I recently needed to publish the contents of an iPhoto library online, so I wrote a script that converts the library to a WordPress site using WordPress’s REST API. The script is available in my iPhoto-WordPress-Export repository on GitHub. Check it out, and then run it like this:
$ ./iphoto2wordpress.php --library=/path/to/photo/library --wordpress=https://www.example.com/
After prompting for a username and password, it will upload all of the library’s photos to the specified WordPress site. For each event in the library, it creates a post that includes a gallery containing all of the images from the event. It will also convert any albums into categories, categorizing the photos themselves, not the posts. (For this to work, you will need to enable categories for attachments.)
If the script stops for any reason, you can restart it, and it will pick up where it left off. Depending on what it was doing when it stopped, you may have an orphaned attachment in your Media.
Posts are created as drafts and left for you to publish at your leisure.
I used this script to create DavidTewes.com. (For back-story on what that site is and how it came to be, see this post.) Because the site is image-centric, I chose a photography based theme called Silvia, and I made a few adjustments to it:
- I added comments to attachment pages.
- I ensured that individual images are included in the search results.
- To make search results look nicer, I added code that causes any attachment to be considered its own post thumbnail.
- I set the default post order to be reversed, so the events are listed in ascending chronological order like they were in the iPhoto library.
I could have had the script automatically assign a featured image to each post, but I chose to make that decision manually. Here’s the end-result:
Let me know if you have any questions, and if you use the script, leave a link to the site you used it on in the comments below!