Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using Wordpress as a CMS for a small business website (not my first choice.) Each product page needs to have a small carousel of images that contains images relevant to the product.

I've set up a custom Post Type for the products and am currently using custom fields to display some information specific to each product. I can't just cut and paste the code for each individual carousel into a custom fields; since, to get the images properly, I need PHP in the code for the carousel.

I also can't use individual custom fields for each image since the number of images in the carousel could be unpredictable.

Is there a good way to do this? Suggestions are appreciated!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use WordPress built in gallery, see Gallery Shortcode. If you look for the gallery shortcode function in WordPress core, you can see how it grabs the image attachments to a post with get_children and outputs them. You can use this as a starting point to write your own function to output the gallery with your own markup and css / js by filtering post_gallery or just ouputting attached images without adding the gallery shortcode to the content.

There are also numerous gallery plugins, some have support for slider scripts. If you search the plugin repository you'll find a few.

Edit- there's also no reason why you can't store n number of images as multiple custom fields with the same key. you'll get an array of images, you just won't be able to manage the order easily. another option is to create your own meta box and manage an array of images yourself using a single custom field. There are a few questions on this site regarding managing images with your own meta box + media library if you search around.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.