Last active
December 20, 2015 13:39
-
-
Save tomjn/6140172 to your computer and use it in GitHub Desktop.
If you're lucky enought o be running WordPress on PHP 5.5, you can use generators for your post loops like this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// with the above we can now do things like this: | |
foreach ( posts_loop() as $p ) { | |
get_template_part( 'content', 'page' ); | |
comments_template( '', true ); | |
} | |
// put this below in your functions.php: | |
// post_loop generator | |
function posts_loop() { | |
global $post; | |
while ( have_posts() ) { | |
the_post(); | |
yield $post; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment