mgason Posted May 20, 2011 Share Posted May 20, 2011 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 https://forums.phpfreaks.com/topic/236932-if-statement-syntax-is-wrong/ Share on other sites More sharing options...
mgason Posted May 20, 2011 Author Share Posted May 20, 2011 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 https://forums.phpfreaks.com/topic/236932-if-statement-syntax-is-wrong/#findComment-1217905 Share on other sites More sharing options...
AgentVIP Posted May 20, 2011 Share Posted May 20, 2011 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 https://forums.phpfreaks.com/topic/236932-if-statement-syntax-is-wrong/#findComment-1217909 Share on other sites More sharing options...
mgason Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks, I cleaned that up, I never really know when I do and do not need the php tags. PHP is not my forte! Link to comment https://forums.phpfreaks.com/topic/236932-if-statement-syntax-is-wrong/#findComment-1217917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.