php - Check for first post using wp_query -
i new wordpress. inside loop want check if post first result query.
this code.
<?php $args = array('post_type' => 'home-slider', 'posts_per_page' => 6, 'order' => 'asc'); $query = new wp_query( $args ); while ($query->have_posts()) : $query->the_post(); ?> <?php if ( ) { ?> // check if first post <p>test</p> <?php } else { ?> <p>test123</p> <?php } ?> <?php endwhile; ?>
thanks in advance.
instead of doing check inside loop, move outside , query first post after if()
statement:
<?php $args = array('post_type' => 'home-slider', 'posts_per_page' => 6, 'order' => 'asc'); $query = new wp_query( $args ); ?> <?php if ($query->have_posts()) : $query->the_post(); ?> <p>test</p> <?php endif; while ($query->have_posts()) : $query->the_post(); ?> <p>test123</p> <?php endwhile; ?>
Comments
Post a Comment