Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Created May 21, 2018 09:03
Show Gist options
  • Save obiPlabon/7cc7897ae269a596842ba1c806218621 to your computer and use it in GitHub Desktop.
Save obiPlabon/7cc7897ae269a596842ba1c806218621 to your computer and use it in GitHub Desktop.
WP The Loop
<?php
/**
* World's simplest secondary The Loop
*/
$posts = get_posts( $args );
if ( count( $posts ) ) :
global $post;
foreach ( $posts as $post ) :
setup_postdata( $post );
the_title( '<h1>', '</h1>' );
endforeach;
wp_reset_postdata();
else :
// Show something to notify there's no post
endif;
<?php
/**
* World's simplest The Loop
*/
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
the_title( '<h1>', '</h1>' );
endwhile;
else :
// Show something to notify there's no post
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment