• Resolved lutzcreativegroup

    (@lutzcreativegroup)


    I have the plugin working well with images loaded to a repeater. The images show along with their captions. If there are no captions with an image it appears to put in the image title. I was hoping for more control over this. I have a field in my repeater to write a caption. My goal is to override the caption associated with the image or the title and use the caption entered in ACF. Is there some way to do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Philipp Bammes

    (@tyrannous)

    Hi @lutzcreativegroup,
    sorry for the delay.

    Since your are using Advanced Custom Fields instead of a native WordPress Gallery the support I can provide here is limited.

    I suggest you to check the filter slick_slider_caption_html (see https://www.ads-software.com/plugins/slick-slider/#faq, question “Is it possible to adjust the caption’s markup?”). For simple usage example, please refer to https://www.ads-software.com/support/topic/dont-fallback-to-title-if-caption-is-blank/#post-8747666,

    I hope this helps.

    Plugin Author Philipp Bammes

    (@tyrannous)

    Hi @lutzcreativegroup,
    have you been able to review my response? I’d really like to see this thread resolved.

    Thread Starter lutzcreativegroup

    (@lutzcreativegroup)

    Sorry, I was exploring other options. The filter you shared does get rid of the titles and only shows the captions associated with the image in the Media Library. This is good, but not exactly what I am trying to accomplish.

    Using ACF, I have a method of adding/organizing photos for a slider. It also allows me to enter an Alternative Caption that would override the caption in the Media Library.

    So I loop through the entries and then populate your shortcode:
    $GalleryCode.=do_shortcode('[gallery slick_active="true" sl_show_caption="true" sl_dots="true" sl_fade="true" type="slideshow" size="large" sl_autoplay="true" ids="'.$GalleryID.'"]');

    I then return $GalleryCode. So I am lookng for a way to insert an alternative caption per slide vs a filter that tells the system to show nothing if there is no slide associated with the image in the Media Library.

    Thread Starter lutzcreativegroup

    (@lutzcreativegroup)

    Here is my complete shortcode:

    function jmore_gallery(){
    	if( have_rows('galleries') ){
    		$GalleryCode='<div id="GalleriesContainer">';
    			while( have_rows('galleries') ): the_row();
    				$GalleryCounter=$GalleryCounter+1;
    				$GalleryID="custom-".$GalleryCounter;
    				$GalleryTitle=get_sub_field('gallery_title');
    				$GalleryArray=array();
    				$CaptionArray=array();
    				$GalleryCode.='<h2>'.$GalleryTitle.'</h2>';
    				$GalleryCode.='<div class="IndividualGalleryContainer">';
    			if( have_rows('image_gallery') ){
    					while( have_rows('image_gallery') ): the_row();
    						$ThisImage=get_sub_field('image');
    						$ThisImageShowCaption=get_sub_field('show_caption');
    						$ThisImageAltCaption=get_sub_field('alternative_caption');
    						$ThisImageID=$ThisImage['id'];
    						array_push($GalleryArray, $ThisImageID);
    						$ThisImageURL=$ThisImage['url'];
    						if($ThisImageShowCaption==1){//If captioning is turned on for this image
    							if(!empty($ThisImageAltCaption)){//Check if there is an Alternative caption added
    								$ThisImageCaption=$ThisImageAltCaption;//Puts the alternative caption in to the variable
    								$ThisImageCaption=str_replace(",",",",$ThisImageCaption);//Replaces commas with HTML character equivelant 
    							}else{
    								$ThisImageCaption=$ThisImage['caption'];//Use caption associated with image from library
    								$ThisImageCaption=str_replace(",",",",$ThisImageCaption);//Replaces commas with HTML character equivelant
    							}	
    						}else{
    							$ThisImageCaption="";
    						}
    						array_push($CaptionArray, $ThisImageCaption);
    					endwhile;//while( have_rows('image_gallery') ): the_row();
    				}
    				$GalleryIDs=implode(",",$GalleryArray);//Puts a comma after each ImageID except for the last one
    				//$GalleryCode.="Gallery IDs: ".$GalleryIDs."<br>";
    				$GalleryCaptions=implode(",",$CaptionArray);//Puts a comma after each Caption except for the last one
    				//$GalleryCode.="Gallery Captions: ".$GalleryCaptions."<br>";
    				//$GalleryCode.=do_shortcode('[soliloquy_dynamic id="'.$GalleryID.'" images="'.$GalleryIDs.'" captions="'.$GalleryCaptions.'"]');
    				$GalleryCode.=do_shortcode('[gallery slick_active="true" sl_show_caption="true" sl_dots="true" sl_fade="true" type="slideshow" size="large" sl_autoplay="true" link="none" ids="'.$GalleryID.'"]');
    				//$GalleryCode.=soliloquy_dynamic( array( 'id' => $GalleryID, 'images' => $GalleryIDs ) );
    				$GalleryCode.='<p>&nbsp;</p></div><!-- /IndividualGalleryContainer -->';	
    			endwhile; // while( has_sub_field('galleries') )
    					$GalleryCode.='</div><!-- /GalleriesContainer -->';
    				}
    	return $GalleryCode;
    }
    add_shortcode('JmoreImageGallery', 'jmore_gallery');
    Thread Starter lutzcreativegroup

    (@lutzcreativegroup)

    By the way, I cannot get the do_shortcode to work with the Slick shortcode.

    Thread Starter lutzcreativegroup

    (@lutzcreativegroup)

    Don’t worry about this. I managed to get a different plugin to do what I wanted. Thanks for the help though.

    Plugin Author Philipp Bammes

    (@tyrannous)

    Hi @lutzcreativegroup,
    I’m glad you where able to solve this.

    Just for the record: The [gallery] shortcode is the native WordPress gallery shortcode. Slick Slider simply filters the HTML output. So do_shortcode( '[gallery ids="1,2,3"]' ); indeed does work (see https://codex.www.ads-software.com/Gallery_Shortcode#Usage).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Control Captions with ACF’ is closed to new replies.