Is there anything wrong with this statement

I’m trying to widgetize a sidebar

The example code is:


<?php if (function_exists('dynamic_sidebar) || !dynamic_sidebar()) : ?>

     <li>Stuff shown here if widgets are not active</li>

<?php endif; ?>


Using this method, it works!

I wanted to get a little creative and try something like this


<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) { ?>
     <li>Stuff shown here if widgets are not active</li>
<?php } endif; ?>


I keep geting Parse error!

What is wrong with my second example?

Perhaps reading this and [url=http://php.net/manual/en/control-structures.alternative-syntax.php]this makes things more clear.
If-statements are either encapsulated by { and } or by ‘if: … endif;’.

It’s either

if:
// some code
endif;

OR

if {
// some code
}

not a combination thereof

you have

if {
// some code
} endif;

You don’t, it’s already ended by the } in the last line

:slight_smile:

Thank you :slight_smile:

Sorry if this is a stupid question…

I’m supposed to end the if statement right?

So if i start an if statement like so:


<?php if ( this statement is false ) { ?>
 // some code
//reason i'm doing it like this is just to experiment
<?php } ?>

How do i end the statement above?

Thank you :slight_smile: