未经测试,但我认为这会成功!
<?php
// Get date Categories
$date_cats = get_categories(array(
\'include\' => \'1,2,3,4\'
));
// Loop through date categories
foreach($date_cats as $date_cat) :
// Get link of current date category
$date_cat_link = get_category_link( $date_cat->cat_ID ); ?>
<ul>
<li><a href="<?php echo $date_cat_link; ?>"><?php echo $date_cat->name; ?></a>
<ul>
<?php
// Get ID of current date category
$date_cat_id = $date_cat->cat_ID;
// Get ABC categories
$abc_cats = get_categories(array(
\'include\' => \'5,6,7\'
));
// Loop through ABC catagories
foreach($abc_cats as $abc_cat) :
// Get ID of current ABC category
$abc_cat_id = $abc_cat->cat_ID;
// Get link of current ABC category
$abc_cat_link = get_category_link( $abc_cat->cat_ID );
// Run a query for posts that are in this date category AND this ABC category
$query = new WP_Query( array(
\'posts_per_page\' => -1,
\'category__and\' => array( $date_cat_id, $abc_cat_id )
));
// If there are posts, show this ABC category\'s name and link
if ( $query->have_posts() ) { ?>
<li><a href="<?php echo $abc_cat_link; ?>"><?php echo $abc_cat->name; ?></a></li>
<?php } ?>
<?php endforeach; ?>
</ul>
</li>
</ul>
<?php endforeach; ?>