Jump to content

jaspn

New Members
  • Posts

    3
  • Joined

  • Last visited

jaspn's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, First up, the project I'm working on is a WordPress theme using the Advanced Custom Fields Pro plugin. However, I don't think knowledge of this plugin will be totally necessary for somebody to help, or to begin pointing me in the right direction. I'm trying to get an image gallery to display, that's nested inside what's called a flexible content block (it works similar to a repeater; note the if and while statements). So far I've been unsuccessful. The structure of my fields are as such: Field Group Flexible Content (page_layout)Layout (heading_text) Layout (body_text) Layout (image_gallery)Gallery (images) Here's the PHP code: <?php // check if the flexible content field has rows of data if( have_rows('page_layout') ): // loop through the rows of data while ( have_rows('page_layout') ) : the_row(); if( get_row_layout() == 'heading_text' ): the_sub_field('heading_level'); the_sub_field('heading_content'); elseif( get_row_layout() == 'body_text' ): the_sub_field('body_text_content'); elseif( get_row_layout() == 'spacer' ): the_sub_field('spacer_height'); elseif( get_row_layout() == 'gallery' ): // check if the nested repeater field has rows of data if( have_rows('images') ): echo '<ul>'; // loop through the rows of data while ( have_rows('images') ) : the_row(); $image = get_sub_field('images'); echo '<li><img src="' . $image['url'] . '" alt="' . $image['alt'] . '" /></li>'; var_dump ($image); endwhile; echo '</ul>'; endif; endif; endwhile; else : // no layouts found endif; ?> In wp-admin (front end editing) I've loaded in three images to the gallery. My output is such: <ul> <li><img src="" alt="" /></li>bool(false) <li><img src="" alt="" /></li>bool(false) <li><img src="" alt="" /></li>bool(false) </ul> So it appears the code is 'sort of working', in that it's finding three images represented by the three <li's>. However, note the empty src and alt fields, and that doing a var_dump on $image gives me back bool(false), when there SHOULD be an array. Does anybody know why the arrays aren't being returned? If it helps, there's some pretty easy to read documentation for the plugin over here: Flexible content field: http://www.advancedcustomfields.com/resources/flexible-content/ Gallery field: http://www.advancedcustomfields.com/resources/gallery/ If anybody could provide some pointers, that would be really great. I'm also keen to know why this isn't working, and what I've done wrong for my own learning. Thank you.
  2. @Chocu3r, that solution worked perfectly, thank you. I'm still unsure how it does work, but I'll have to look into it further.
  3. Hi, I'm a PHP beginner, so I don't know if this question should be placed in PHP>general or PHP>applications forum. I assume this forum because I'm coding some PHP to integrate a WordPress plugin called Custom Field Suite. I believe the foundation of this code is generic PHP in nature and not plugin specific, so I think somebody should be able to help me regardless of their WP or CFS experience. I've got the basics of this plugin down pat, and have been happily creating custom fields in the WordPress interface and displaying them successfully using the plugin's php code from the API reference page (link below). I've just come across an issue where I need to create a page which allows my client to add any amount of image galleries, with any amount of images inside each gallery. To create this, I've began with a foreach loop called image_galleries containing a gallery_title. Then inside that I've created another foreach loop called gallery_images, which is nested inside image_galleries. The gallery_images foreach loop contains two simple fields for the file url and image alt text. So far my attempt to get this displaying in-browser has failed - only the surrounding HTML code is displayed on the page, and nothing inside the <p> or two <h2> tag is output to HTML. Here's the raw PHP code: <p> <?php $fields = CFS()->get('image_galleries'); foreach ($fields as $field) { ?> <h2><?php echo CFS()->get('gallery_title'); ?></h2> <?php $fields = CFS()->get('gallery_images'); foreach ($fields as $field) { echo '<a href="' . $field['image_url'] . '" data-lightbox="anstie_images"><img src="' . $field['image_url'] . '" alt="' . $field['image_alt_text'] . '" class="thumbnails" /></a>'; } //end nested foreach loop } //end parent foreach loop ?> </p> It's worth noting that the plugin author does have some code reference to integrate loops, but there's nothing on nested loops: http://customfieldsuite.com/docs/loop/. A google search found one post from a few years ago on the subject that contains deprecated code. My apologies if my explanation is a bit long winded. It's probably a simple solution (which I've not been able to find on my own as yet) but I thought a bit of background knowledge and my method to date may help provide any clues. Your assistance is appreciated. Many thanks. jaspn
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.