I’ve been working with ACF Pro on and off for a few years. My level of PHP is not great, but I continue to learn.
Over time I’ve been able to create a list of thumbnails each linked to a Lightbox for the full sized images. I’ve also have created a slideshow for other sized images each linked to a Lightbox for the full sized images. The common element from these two examples is that I used the ACF Pro Gallery Feature from ONE post on each example.
Now, I’m trying to create a list of thumbnails from a “series of posts” and I’m not finding a solution. I’ve created a CPT, each has a gallery and a separate image using ACF Pro. The separate image is to be displayed in the thumbnail list and will have its own slideshow from its own post using the ACF Pro Gallery. It’s not working and I can’t seem to find a solution from the support section mostly because I’m not a great PHP coder.
Can anyone recommend a template/theme using this type of combination that already has the code written? Perhaps, point me in the right direction to write the code? I’ve been racking my brain trying to figure how to write this loop and the code has become a mess. I’m interested in hiring help if that what it takes.
Your feedback is greatly appreciated.
Here’s a simple example how to get the thumbnail images from the CPT posts:
<?php $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'custom_post_type_slug' )); if( $posts ): ?> <ul> <?php foreach( $posts as $post ): setup_postdata( $post ) ?> <li> <?php $image = get_field('thumbnail_field_name'); ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> </li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); ?> <?php endif; ?>
Where ‘custom_post_type_slug’ is the slug of your CPT and ‘thumbnail_field_name’ is the name of your image custom field. These pages should give you more idea about it: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ and https://www.advancedcustomfields.com/resources/image/.
If you want to learn PHP, I recommend you checking this site: http://www.w3schools.com/php/. If you don’t have the time to do it, I suggest you hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/ or https://www.upwork.com/.
Hope this helps 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!