Jump to content

if statement syntax is wrong


mgason

Recommended Posts

Hi,

I am no PHP expert. I can poke about, do a little cut and paste.

Dreamweaver is telling me I have a syntax issue with my if statement. I have tried a few things without success.

Dreamweaver says the error is on the else line, that may not be true. please show me what I am doing wrong.

Thanks Mark

<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
			 $block_1 = get_custom_field('cft_tinymce_1');
			if( $block_1 ) { ?>
				<?php echo $block_1; ?> 
					<?php } ?>
					<?php else { ?>
						<?php the_content(); ?>
					<?php } ?>
				</div> <!-- End tec-event-entry -->

Link to comment
Share on other sites

I may have sorted it, is this correct? Is it the best way?

					<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
			 $block_1 = get_custom_field('cft_tinymce_1');
			if( $block_1 ) { ?>
				<?php echo $block_1; ?> 
					<?php } else { ?>
						<?php the_content(); ?>
					<?php } ?>
				</div> <!-- End tec-event-entry -->

Link to comment
Share on other sites

The second code looks good. As you figured out, the '} else {' statement should be together. However, you still don't really need all of those PHP tags. You could look into ternary operators to make it even simpler, but for general basic purposes, this was is fine

 

<div class="entry-content tec-event-entry">						 
<?php
/** Get the "cft_tinymce_1" custom field */
	$block_1 = get_custom_field('cft_tinymce_1');
if($block_1) {
	echo $block_1;
} else {
	the_content();
}
?>
</div>
<!-- End tec-event-entry -->

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.