have post wordpress code example
Example 1: wordpress loop first two post
<div class="col-lg-12">
<div class="row">
<?php if ( have_posts() ) : ?>
<?php if ( in_category( 'Featured' ) ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<?php if( $wp_query->current_post == 0 ) {
?>
<?php } ?>
<?php if( $wp_query->current_post <= 1 ) {
get_template_part( 'content', 'featured' );
?>
<?php } ?>
<?php if( $wp_query->current_post == 1 || $wp_query->current_post <= 1 && $wp_query->current_post == $wp_query->post_count-1 ) {
?>
<?php } ?>
<?php if( $wp_query->current_post == 2 || $wp_query->current_post <= 1 && $wp_query->current_post == $wp_query->post_count-1 ) {
?>
<?php } ?>
<?php if( $wp_query->current_post >= 2 ) {
get_template_part( 'content', 'featuredside' );
?>
<?php } ?>
<?php if( $wp_query->current_post == 4 || $wp_query->current_post == $wp_query->post_count-1 ) {
?>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
Example 2: have_posts()
NOTE: The functions, have_posts(); and the_post(); are tied to the default automatic query that wordpress makes
on its on using the current URL.
Example 3: have post wordpress
if ( have_posts() ) :
while ( have_posts() ) : the_post();
endwhile;
else :
_e( 'Sorry, no posts were found.', 'textdomain' );
endif;