If/While (second not working)

Can somebody explain to me what the difference is between:

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

Read More

and

<? php if (have_posts()) { while ( have_posts() ) { the_post(); } } ?>

Related posts

Leave a Reply

1 comment

  1. Besides the fact that you can’t have a space between the <? php…They’re both the same.

    The first is what’s referred to as the alternative syntax for control structures.

    The full statements should look something like:

    <?php if (have_posts()) : while ( have_posts() ) : the_post(); ?>
        <!-- Your post html -->
    <?php endwhile; endif; ?>
    

    And…

    <?php if (have_posts()) { 
              while ( have_posts() ) { 
                  the_post(); ?>
    
         <!-- Your post html -->
    
    <?php } } ?>