Created
November 6, 2015 06:56
-
-
Save rayflores/a925a2bd37504d5a322d to your computer and use it in GitHub Desktop.
close loop after each term
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 | |
/** | |
* Theme: Flat Bootstrap | |
* | |
* Template Name: ACF Lathes | |
* | |
* This is the most generic template file in a WordPress theme | |
* and one of the two required files for a theme (the other being style.css). | |
* It is used to display a page when nothing more specific matches a query. | |
* E.g., it puts together the home page when no home.php file exists. | |
* Learn more: http://codex.wordpress.org/Template_Hierarchy | |
* | |
* @package flat-bootstrap | |
*/ | |
get_header(); ?> | |
<?php get_template_part( 'content', 'header' ); ?> | |
<div class="container"> | |
<div id="main-grid" class="row"> | |
<section id="primary" class="content-area col-md-8"> | |
<main id="main" class="site-main" role="main"> | |
<?php | |
wp_reset_postdata(); | |
$term_id = 20; | |
$tax_name = 'category'; | |
$termchildren = get_term_children( $term_id, $tax_name ); | |
$i=1; | |
foreach ( $termchildren as $child ) { | |
echo '<div class="'. $i . '-term">'; | |
$child_term = get_term_by( 'id', $child, $tax_name ); | |
$args = array( | |
'post_type' => 'inventory', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => $child_term->slug, | |
), | |
), | |
); | |
$query = new WP_Query( $args ); | |
?><div class="<?php echo $i; ?>-post"> | |
<?php // output the term name in a heading tag | |
echo'<h2 style="background:#94A6C6;padding:5px 0 5px 20px;font-weight:bold;">' . $child_term->name . '</h2>'; | |
// Start the Loop | |
while ( $query->have_posts() ) : $query->the_post(); ?> | |
<div class="<?php echo $child_term->name; ?>-listing" id="post-<?php the_ID(); ?>"> | |
<div class="post-thumb" style="width:27%;float:left;"> | |
<a href="<?php the_permalink(); ?>"><?php | |
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. | |
the_post_thumbnail('inventory-size'); | |
} ?> | |
</a> | |
</div> | |
<div class="post-content"> | |
<a href="<?php the_permalink(); ?>"> | |
<h4><?php the_field('name') ?></h4> | |
</a> | |
</div> | |
</div> | |
<?php | |
endwhile; | |
echo '</div>'; $i++; | |
// use reset postdata to restore orginal query | |
wp_reset_postdata(); | |
} | |
?> | |
</main><!-- #main --> | |
</section><!-- #primary --> | |
<?php get_sidebar(); ?> | |
</div><!-- .row --> | |
</div><!-- .container --> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment