好吧,我不知道这看起来怎么样,但我已经得到了我想要的。
<?php
$term = get_queried_object();
$tax = \'ntp_package_type\';
$parents = $term->parent;
$term_id = $term->term_id;
if($parents == 0 && !is_single()){
wp_list_categories( array (
\'taxonomy\' => \'ntp_package_type\',
\'pad_counts\'=> 0,
\'title_li\' => \'\',
\'child_of\' => $term_id,
)
);
}
elseif ($parents > 0 && is_tax($tax, $tax->name)){
$args = array(
\'post_type\' => \'ntp_package\',
$tax => $term->name,
);
echo "<h2>".$term->name."</h2>";
$wp_query = new WP_Query($args);
if( $wp_query->have_posts() ):
while ( $wp_query->have_posts() ) : $wp_query->the_post();
echo "<p><a href=\\"".get_permalink()."\\">".$post->post_title."</a></p>";
endwhile;
endif;
wp_reset_postdata();
wp_list_categories( array (
\'taxonomy\' => \'ntp_package_type\',
\'pad_counts\'=> 0,
\'title_li\' => \'\',
\'child_of\' => $term->parent,
\'exclude\' => $term_id,
)
);
}
elseif(is_single()){
$single = get_queried_object();
$sing_id = $single->ID;
$singterm = wp_get_post_terms($sing_id, $tax);
$singterm_slug = $singterm[0]->slug;
$singterm_parent = $singterm[0]->parent;
$singterm_id = $singterm[0]->term_id;
$args = array(
\'taxonomy\' => $tax,
\'term\' => $singterm_slug,
);
?>
<h2>
<a href="<?php echo get_term_link($singterm_slug, $tax); ?>"><?php echo $singterm[0]->name; ?> </a>
</h2>
<?php
$singquery = new WP_Query($args);
while ($singquery->have_posts()) : $singquery->the_post();
?>
<p>
<a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
</p>
<?php
endwhile;
wp_reset_postdata();
wp_list_categories( array (
\'taxonomy\' => \'ntp_package_type\',
\'pad_counts\'=> 0,
\'title_li\' => \'\',
\'child_of\' => $singterm_parent,
\'exclude\' => $singterm_id,
)
);
}
?>