Adding PHP to my theme generates error

For a new Wordpress template I am developing I need to create a Bootstrap carousel that takes data from a custom filed I have created.

I need to add this PHP code but when I do and I refresh the page I get an error in Wordpress.

This is the code

<?php


// *Repeater
// carousel_repeater
// *Sub-Fields
// carousel_image
// carousel_text

// check if the repeater field has rows of data
if( have_rows('carousel_repeater') ):

echo	 '<div id="carouselExamplethumbs" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">';

// loop through the rows of data for the tab header
$i = 0; // Set the increment variable
while ( have_rows('carousel_repeater') ) : the_row();
	
	$image = get_sub_field('carousel_image');
	$text = get_sub_field('carousel_text');



 <div class="carousel-item <?php if($i == 0) echo 'active';?> active">
 	<img class="d-block w-100" alt="<?php echo $image['title']; ?>" src="&lt;blocs-php-snippet> echo $image['url']; &lt;/blocs-php-snippet>">
 	<div class="carousel-caption d-block">
 		<?php echo $text; ?>

	</div>
</div>

              
    <?php   $i++; // Increment the increment variable

endwhile; //End the loop 
echo '?></div>';
$i = 0; // Set the increment variable

echo '<ol class="carousel-indicators position-relative">';
		
// loop through the rows of data for the tab header
while ( have_rows('carousel_repeater') ) : the_row();

	$image = get_sub_field('carousel_image');
	$text = get_sub_field('carousel_text');


<li class="w-100 h-100 active" style="text-indent:0" data-target="#carouselExamplethumbs" data-slide-to="<?php echo $i;?>"><img src="&lt;blocs-php-snippet> echo $image['url']; &lt;/blocs-php-snippet>" class=""></li>
		
<?php   $i++; // Increment the increment variable	

endwhile; //End the loop  
	
echo '?></ol>';

echo '<a class="carousel-control-prev" href="#carouselExamplethumbs" role="button" data-slide="prev">
		    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
		    <span class="sr-only">Previous</span>
		  </a>
		  <a class="carousel-control-next" href="#carouselExamplethumbs" role="button" data-slide="next">
		    <span class="carousel-control-next-icon" aria-hidden="true"></span>
		    <span class="sr-only">Next</span>
		  </a>
	</div>';

else :

// no rows found

endif;?>

There is an error in the PHP or am I adding it wrong? I am using the custom code Brick.

the error I get is this

Parse error: syntax error, unexpected ‘<’ in /Users/mikes/Local Sites/wsite/app/public/wp-content/themes/wsite/single-prod.php on line 88

Try disabling the preview of the custom code. It may be being escaped by the Blocs design canvas.

https://help.blocsapp.com/knowledge-base/html-widget/#in-app-previewing

That did the job!

Thanks @Norm :slight_smile:

1 Like