I was browsing a WordPress site, and spotted this line
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>
<li id="recent-posts">
<ul>
<?php get_archives('postbypost', 5); ?>
<ul>
</li>
<?php endif; ?>
What do the colon before and after else do exactly? How does this thing work?
That function will only execute
dynamic_sidebarif it’s already declared. The colons are PHP’s alternate syntax for control structures. They’re meant to be used in templates/views.In this case, it looks like the
ifhas an empty body and it’s only used to calldyanamic_sidebarif it exists, since the call todynamic_sidebar(1)will not occur if the first boolean check fails.elsewill output anything between itself and the<?php endif; ?>. In this case, it would fire when the functiondynamic_sidebardoes not exist or ifdyanmic_sidebar(1)does not returntrue.