Support

Account

Home Forums Front-end Issues Issues with Basic Gallery

Solving

Issues with Basic Gallery

  • Hi, hoping this is the right place to ask this. We are trying to get a very basic WP gallery implementation working and having some issues.

    We have a Custom Post Type for our projects using ACF for fields. We have an ACF field that allows a typical WP gallery to be added using the WYSIWYG editor. There are also other ‘Image’ fields for thumbnails used in other ways. This all seems to work fine.

    Then, for the front-end display, we simply use:
    <?php echo do_shortcode('[gallery orderby="menu_order" link="none" size="large" columns="1"]'); ?>

    ISSUES:
    We notice 2 things that are not as desired:
    1) The gallery displays ALL images that are attached to the CPT, and none that are not. So it can differ from what actual images we’ve added in the gallery unless those just happen to line-up.

    2) It seems to ignore the “menu_order” orderby option (as described here). All other ordering options appear to work correctly, but we really need to be able to set the order manually using drag-n-drop.

    – Any ideas???

    It seemed like such a simple implementation (i.e., no pop-up lightbox, HTML5 markup, default WP responsive images, etc.).

    THANKS!

  • While you are using an ACF WYSIWYG you’re not using an ACF gallery field. Just a basic WP Gallery. From your description, it is working like it’s supposed to.

    To show only images that you want to show, or images that are attached to other posts you’ll need to use the “include” setting that is shown on the page you linked to. To do this you can click on the gallery edit icon to select images. The “menu_order” value specifies that the order should be the order you set them to by editing this gallery as well.

  • OK, thanks. Yeah, we prefer to stick with default WP functionality wherever possible (less dependencies or possible conflicts with updates), so was hoping something this basic would work OK.

    But I’m guessing we’re probably not going about displaying the gallery properly (I’m a def PHP novice). As we obviously can’t specify ID’s to include in the ‘echo do_shortcode’ statement, it’s appearing that it won’t by default respect what is done in the Admin editor (where it IS correct).

    When I add the same gallery code to the default post content field, the gallery DOES display as expected (only showing selected images, and in order specified). We were going to use that for other purposes, but maybe I can just re-arrange how and where things are added. The end-user would then just need to be on-top of the variables (e.g., large images, link to ‘none’, etc.).

    I’m sure there must be a way to get the same functionality from the ACF WYSIWYG field as from the default content field, just not sure how exactly to go about it…

  • I’m a little confused. What version of ACF are you using? Also, are you putting the standard gallery tag [gallery] in an ACF WYSIWYG editor or in some other way?

  • Hi. We are using ACF 4.4.11 on WP 4.7.3. Now we do also use TinyMCE Advanced as our editor (have been for years), but it’s usually compatible with things.

    In Admin, we add galleries in standard WP fashion, using ‘Add Media’ button and media interface. I can’t see the actual shortcode in the WYSIWYG editor, as there is no ‘Visual/Text’ tab, but when I copy/paste it into the main content area and examine, the shortcode looks perfectly fine.

    As a test, I manually added the desired photo IDs to the ‘do_shortcode’ statement in the template file, and that did cause it to only show those specific photos. But it still didn’t follow the order properly. So there must be something unique in how the WP gallery shortcode is parsed in the standard content field.

  • If you use do_sortcode or you add the shortcode to the normal content area they are parsed the same. ACF 4 does not use the standard WP editor for its WYSIWYG fields, but it does it just calls do_shortcode, basically it just applies the same filters that WP does to the content in the standard editor. As far as I know there’s noting in ACF that would cause the standard WP gallery shortcode to function incorrectly.

    I just testing on a site using ACF 4, adding a gallery to both the standard WP editor and to an ACF WYSIWYG field. I added different images to each and reordered them in both. For both galleries the images appear I selected appeared in the order that I set them.

    The only thing that I can come up with is that you have something else on the site interfering with the operation of the WP gallery shortcode. What other plugins are you running? Try deactivating them. What theme are you using? It could be something in the theme.

  • Thanks for the continued help, much appreciated!

    I think I was able to get it working by altering the code to display the gallery in my template file. Instead of using:
    echo do_shortcode('[gallery orderby="menu_order" link="none" size="large" columns="1"]')

    I’m now using:

    <?php if ( '' !== ( $gallery = get_post_meta( get_the_ID(), 'project_gallery', true ) ) ) : ?>
                    <section class="project-gallery"> 
    		<?php echo do_shortcode( $gallery ); ?>
                    </section>
                <?php endif; ?>
    

    The ‘if’ statement was already wrapping my original code, I just wasn’t taking advantage of it properly. Someone else had started this plugin for us, and I was just trying to get it working (with my limited PHP knowledge).

    It now functions just like a gallery added to the main content area, so we do have to make sure all variables are accounted for there (e.g, link=none, size=large, etc.). But this is fine.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.