Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Okay so I kind of understand that ternary operators work like

  condition ? TRUE : FALSE

However I'm looking a simple loop to get my posts that I have

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

The question I have is where is the ? in this syntax. Why is the : used when according to the

   condition ? TRUE : FALSE

Whatever comes after the semicolon is when that statement (like have_posts()) is FALSE?

share|improve this question

1 Answer 1

The double colon in this case is part of the alternative syntax for control structures.
That's not the ternary operator.

You could also write instead:

if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();
        the_content();
    }
}

I prefer the second style, most code editors enable automatic folding with it, so I can close parts I don't need to see.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.