This basically shows the posts of the site in a layout like, 1 row image + text, and the next row text + image, but when there is no image, it only displays text in the entire row.I want to know a better way to write this code.  I know there are some repeated code, but I don't know how to handle it another way. <article id=post-<?php the_ID(); ?> <?php post_class(); ?> ><div class=row>        <!-- If the current post is even display the image -->        <?php if ($wp_query->current_post % 2 == 0): ?>        <span class=col col-sm-5>            <!-- Get the featured image -->            <?php if ( has_post_thumbnail() ):  ?>                 <?php the_post_thumbnail( 'full', array( 'class' => 'p-img' ) ); ?>            <?php endif; ?>        </span>        <?php endif; ?>        <?php if ( has_post_thumbnail() ):  ?>             <section class=entry-content col col-sm-7>        <?php else: ?>              <section class=entry-content col col-sm-12>        <?php endif; ?>            <header class=entry-header>                <?php the_title( sprintf( '<h1 class=entry-title><a href=%s rel=bookmark>', esc_url( get_permalink() ) ), '</a></h1>' ); ?>            </header><!-- .entry-header -->            <?php the_excerpt(); ?>            <?php                wp_link_pages( array(                    'before' => '<div class=page-links>' . __( 'Pages:', 'site' ),                    'after'  => '</div>',                ) );            ?>        </section><!-- .entry-content -->        <!-- If the current post is NOT even display the image -->        <?php if ($wp_query->current_post % 2 != 0): ?>            <span class=col col-sm-5>                <!-- Get the featured image -->                <?php if ( has_post_thumbnail() ):  ?>                     <?php the_post_thumbnail( 'full', array( 'class' => 'p-img' ) ); ?>                <?php endif; ?>            </span>        <?php endif; ?></div>  <?php if ( ! has_post_format( 'quote' )) { ?>    <footer class=entry-footer col col-sm-12>        <?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>            <?php                /* translators: used between list items, there is a space after the comma */                $categories_list = get_the_category_list( __( ', ', 'site' ) );                if ( $categories_list && site_categorized_blog() ) :            ?>            <span class=post-author>                By  <?php echo get_the_author_link(); ?> |            </span>            <span class=post-time>                <?php the_time('M j, Y') ?> |            </span>             <span class=cat-links>                <?php printf( __( 'Posted in %1$s', 'site' ), $categories_list ); ?> |            </span>            <?php endif; // End if categories ?>            <span class=read-more-link pull-right>                <a class=read-more href=<?php echo get_permalink( get_the_ID() ) ?>>Read More</a>            </span>            <?php                /* translators: used between list items, there is a space after the comma */                $tags_list = get_the_tag_list( '', __( ', ', 'site' ) );                if ( $tags_list ) :            ?>            <!-- <span class=tags-links>                <?php printf( __( 'Tagged %1$s', 'site' ), $tags_list ); ?>            </span> -->            <?php endif; // End if $tags_list ?>        <?php endif; // End if 'post' == get_post_type() ?>        <?php edit_post_link( __( 'Edit', 'site' ), '<span class=edit-link>', '</span>' ); ?>    </footer><!-- .entry-footer --><?php } ?></article><!-- #post-## -->
Displaying site posts in a layout based on image
php;wordpress