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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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