• Resolved ChrisLomax

    (@chrislomax)


    I noticed the content which the site was currently rendering is output to the buffer early if there are no gallery items.

    This was because ob_end_clean(); was being called regardless of whether there were items in the carousel or not. It flushed the content of the current ACF field I was using straight to the buffer and into the body tag of the page.

    I made the following changes.

    I declare $output just under $images = array();
    I moved
    $output = ob_get_contents();
    ob_end_clean();
    to be inside the if(count($images) > 0){ so the flush is only called if the images are being rendered.

    https://www.ads-software.com/plugins/cpt-bootstrap-carousel/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ChrisLomax

    (@chrislomax)

    Full code

    if(count($images) > 0){
    		ob_start();
    		?>
    		<div id="cptbc_<?php echo $id; ?>" class="carousel slide" data-ride="carousel" data-interval="<?php echo $atts['interval']; ?>">
    			<?php if( count( $images ) > 1 ){ ?>
    				<ol class="carousel-indicators">
    				<?php foreach ($images as $key => $image) { ?>
    					<li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
    				<?php } ?>
    				</ol>
    			<?php } ?>
    			<div class="carousel-inner">
    			<?php foreach ($images as $key => $image) {
    				$linkstart = '';
    				$linkend = '';
    				if($image['url']) {
    					$linkstart = '<a href="'.$image['url'].'"';
    					if($image['url_openblank']) {
    						$linkstart .= ' target="_blank"';
    					}
    					$linkstart .= '>';
    					$linkend = '</a>';
    				}
    			?>
    				<div class="item <?php echo $key == 0 ? 'active' : ''; ?>" id="<?php echo $image['post_id']; ?>" <?php if($atts['use_background_images'] == 1){ echo ' style="height: '.$atts['background_images_height'].'px; background: url(\''.$image['img_src'].'\') no-repeat center center ; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;"'; } ?>>
    					<?php if($atts['use_background_images'] == 0){ echo $linkstart.$image['image'].$linkend; } ?>
    					<?php if($atts['showcaption'] === 'true' && strlen($image['title']) > 0 && strlen($image['content']) > 0) { ?>
    						<div class="carousel-caption">
    							<?php echo $atts['before_title'].$linkstart.$image['title'].$linkend.$atts['after_title']; ?>
    							<?php echo $atts['before_caption'].$linkstart.$image['content'].$linkend.$atts['after_caption']; ?>
    						</div>
    					<?php } ?>
    				</div>
    			<?php } ?>
    			</div>
    			<?php if( count( $images ) > 1 ){ ?>
    				<?php if($atts['showcontrols'] === 'true' && $atts['twbs'] == '3') { ?>
    					<a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
    					<a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
    				<?php } else if($atts['showcontrols'] === 'true'){ ?>
    					<a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">a€1</a>
    					<a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">a€o</a>
    				<?php } else if($atts['showcontrols'] === 'custom' && $atts['twbs'] == '3' &&  $atts['customprev'] != '' &&  $atts['customnext'] != ''){ ?>
    					<a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="<?php echo $atts['customprev'] ?> icon-prev"></span></a>
    					<a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="<?php echo $atts['customnext'] ?> icon-next"></span></a>
    				<?php } ?>
    			<?php } ?>
    		</div>
    		<script type="text/javascript">
    			jQuery(document).ready(function() {
    				jQuery('#cptbc_<?php echo $id; ?>').carousel({
    					interval: <?php echo $atts['interval']; ?>
    				});
    			});
    		</script>
    
    <?php
    	$output = ob_get_contents();
    	ob_end_clean();
    }
    Plugin Author Phil Ewels

    (@tallphil)

    Cool! Thanks for this – I’ll add it as an issue to make sure that it goes out with the next release..

    Phil

    Plugin Author Phil Ewels

    (@tallphil)

    Oops, missed this on the release sorry. Marked as an issue on github so will get cleared up on the next round.

    https://github.com/ewels/cpt-bootstrap-carousel/issues/53

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page is skewed when no carousel items’ is closed to new replies.