Skip to content

Instantly share code, notes, and snippets.

@joshespi
Last active May 28, 2023 15:57
Show Gist options
  • Save joshespi/be373c94c0b7fae24b427e0d374c5ae5 to your computer and use it in GitHub Desktop.
Save joshespi/be373c94c0b7fae24b427e0d374c5ae5 to your computer and use it in GitHub Desktop.
basic wordpress loop
<?php
// Start “The Loop”
if ( have_posts() ) : // Does our website have any posts to display?
while ( have_posts() ) : the_post(); // If the answer is “yes”, let’s run some code.
the_title( '<h2>', '</h2>' ); // Let’s display the title of our post.
the_content(); // Let’s display the content of our post.
endwhile; // There are no more posts to display, let’s shut this down.
else : // If we don’t have any posts, let’s display a custom message below.
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif; // OK, we can stop looking for posts now.
// End of “The Loop”
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment