Advertising


Those Pesky Alternative Control Structures

I’m sure that if you’ve ever decided to build a theme in Wordpress, you’ve had to deal with the The Loop. The Loop is the structure that really is at the heart of the blog engine and looks something like this:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

�.

<?php endwhile; ?>

<?php else : ?>

�.

<?php endif; ?>

(The dots, being the code you use to process each of the individual posts.)

Of course, this is all well and good, but if you’re a beginner to PHP, I’m sure you are a bit confused as to what you are seeing. What are those colons doing there, are where are the curly braces? The answer is that our example is utilizing alternative control syntax in PHP to make the code just a bit more readable. Other templating systems, such as Savant, use this inside templates to make it easier to read where loops and logic statements end. After all endwhile is easier to see at a first glance than a curly brace �}� when reading code mixed with HTML, which describe templates to a ‘T’.




Leave a comment

You must be logged in to post a comment.