0
在wordpress中,以下函數將回顯一個類別列表,其中每個類別名稱下面的每個類別都有關聯的職位。WordPress的 - 列出每個類別下的職位類別的層次結構
這工作正常,除了這會產生一個平面結構的事實。有些類別是兒童類別的其他類別,我希望能夠輸出與此匹配的結構的列表(有點像網站地圖)
是否有人能夠幫助我弄清楚如何修改此代碼以實現此目的?
function posts_by_category() {
//get all categories then display all posts in each term
$taxonomy = 'category';
$param_type = 'category__in';
$term_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach($terms as $term) {
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if($my_query->have_posts()) { ?>
<div class="category section">
<h3><?php echo ''.$term->name;?></h3>
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
<?php
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
}