Skip to content

Instantly share code, notes, and snippets.

@tomjn
Last active Dec 20, 2015
Embed
What would you like to do?
If you're lucky enought o be running WordPress on PHP 5.5, you can use generators for your post loops like this
<?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