function child_do_custom_loop() {
//first get the current term
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // get term
$parent = get_term($term->parent, get_query_var('taxonomy') ); // get parent term
$children = get_term_children($term->term_id, get_query_var('taxonomy')); // get children
if(($parent->term_id=="") && (sizeof($children)>0)) { // no parent, has child - core main categories
$args = array(
'child_of' => $term->term_id,
'taxonomy' => $term->taxonomy,
'hide_empty' => 0,
'hierarchical' => true,
'orderby'=>'menu_order',
'depth' => 1,
'title_li' => ''
);
$category = get_categories($args);
foreach ($category as $subcat) {
wp_reset_query();
echo "<h3>" . $subcat->name . "</h3>"; //Get Parent Category Name
$newargs = array(
'post_type' => 'health-topics',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'slug',
'terms' => $subcat->slug,
),
),
);
$posts = new WP_Query($newargs);
while($posts->have_posts()) : $posts->the_post(); ?>
<h5 id="post-<?php the_ID(); ?>" style="margin-left:20px;">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h5><?
endwhile;
} // end foreach
//echo "i have NO parent, but have children";
}elseif(($parent->term_id!="" && sizeof($children)>0)) { // has parent and child - mid level cats, we dont have these yet
//echo "i have a parent, and children";
}elseif(($parent->term_id=="") && (sizeof($children)==0)){ ?>
<h5>Articles</h5> <?
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h5 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h5><?
endwhile;
endif;
//echo "i have NO parent and NO children";
}elseif(($parent->term_id!="") && (sizeof($children)==0)) { // has parent, no child - last branch on tree
?><h3>Articles</h3> <?
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h5 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h5> <?
endwhile;
endif;
//echo "i have a parent, but NO children";*/
}
}
/* END */
}