How does the ternary operator work in the wordpress loop post?

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

Read More
<?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?

Related posts

Leave a Reply

1 comment

  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.