public
Last active

Looping WP Loops

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php
/*
Useful for minimizing code when you need to make multiple WP_Queries. Ignore the weird variable names. Used originally on a site with CPTs and taxonomies. Adapt as necessary.
*/
//Collect taxonomies to query.
$skeelzray = array('still-life','landscape','portrait');
$skeelz = array();
//Create array of objects
foreach($skeelzray as $skeel) {
$skeelz[] = new WP_Query('posts_per_page=3&post_type=projects&skill='.$skeel);
}
//Loop through the array of objects
foreach($skeelz as $skeel) { ?>
<div id="<?php echo $skeel->query['skill']; ?>">
<h2><a href="<?php echo get_bloginfo('url').'/skill/'.$skeel->query['skill']; ?>"><?php echo $skeel->query['skill']; ?></a></h2>
<?php if($skeel->have_posts()) : while($skeel->have_posts()) : $skeel->the_post(); ?>
<div class="project small">
<a href="<?php the_permalink(); ?>" rel="bookmark" >
<?php the_post_thumbnail("ttrust_one_fourth_cropped", array('class' => 'thumb', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
<span class="title"><span><?php the_title(); ?></span></span>
</a>
</div>
<?php endwhile; endif; ?>
</div>
<?php } ?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.