Basically there are two parts to creating something like this. There has to be code to create the interface in the admin section that lets a user add images to create the gallery and store the data in the WordPress database. The second is code in the theme itself that retrieves the data from the database and converts it into an actual image gallery on the webpage.
This plugin does step 1. Step 2 I’ve left to theme developers, because it means that they can be flexible. Data is stored as single text entry, with the image IDs separated by commas. You need to add code in the theme template file to retrieve this data, then split it into an array, and then loop through the array. Inside this array loop, you have to convert the image ID into the URL of the image, and create the HTML.
The example code that you listed in your question retrieves the data using a custom function which I’ve built in, that does the conversion from comma-delimited string to array for you. It gets the array, then it loops through using the foreach. It gets each image’s URL using the WordPress function wp_get_attachment_url(); This code will end up giving you a list of images.
If you place that on single.php, it’ll be the full gallery. You can tweak it to get just the first image of the gallery for the homepage. You can do this by using this code get_post_gallery_ids($post->ID,1);. The 1 will tell it to just grab a single item. It’ll still be an array though, so still do the for loop.
Given the large number of people wanting pre-built galleries, I’m considering writing a few examples and including them. If the plugin had something like that included, would it be helpful to you?
Since you haven’t responded I’m going to mark this as resolved. If you still have questions, add a comment here and change the status back to un-resolved.
Given the large number of people wanting pre-built galleries, I’m considering writing a few examples and including them. If the plugin had something like that included, would it be helpful to you?
Andy, For Step 2 that you mention, I’ve tried placing the above code in my child theme CSS, but with no luck. Would you be kind enough to post the code that I need to place and where. (Sorry, my CSS skills are not the best. Don’t feel you are insulting me by using a paint-by-numbers approach!)
Thanks!
Paul