我是显示帖子类别子列表。列表显示全部 我只需要显示6(孩子) 帮助我们......
例如: 菜单(父母) list1(孩子) list2(孩子) list3(孩子) list4(孩子) list5(孩子) list6(孩子) list7(孩子) list8(孩子)
<?php $article_categories = get_categories(array(
'child_of' => get_category_by_slug('work')->term_id
));
$talentChildren = get_categories(array('child_of' => get_category_by_slug('talent')->term_id));
?>
<?php if ( have_posts()) : ?>
<?php $talent_Children = array($talentChildren[0]); ?>
<?php foreach($talent_Children as $talent): ?>
<?php
$talentSubChildren = new WP_Query();
$talentSubChildren->query(array('category_name' => $talent->slug));
?>
<h2><a href="<?php the_permalink() ?>talent/directors/"><?php echo $talent->name; ?></a></h2>
<ul>
<?php while ($talentSubChildren->have_posts()) : $talentSubChildren->the_post(); ?>
<li>
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</h4>
</li>
<?php endwhile; ?>
</ul>
<?php endforeach; ?>
<?php endif; ?>
</div>
答案 0 :(得分:5)
您可以在get_categories函数中使用用户编号= 6,如
$talentChildren = get_categories(array('child_of' => get_category_by_slug('news')->term_id,'number' => 6,'hide_empty' => 0));
foreach($talentChildren as $talent):
echo "<pre>";
print_r($talent);
echo "</pre>";
endforeach;