2014-10-17 55 views
4

我显示类别后孩子list.list显示所有 我需要显示只有6个(孩子) 帮助我们......如何设置分类列表限制?

例如: 菜单(父) 列表1(子) 列表2(子) 项目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> 

回答

5

你可以用户号码= 6的get_categories功能类似于

$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; 
+0

我接收 - >语法错误,意想不到 '=>'(T_DOUBLE_ARROW)如何解决编辑这个错误 – Kannan 2014-10-17 11:30:21

+0

。 pl现在试试 – 2014-10-17 11:40:00

+0

你尝试过吗?工作? – 2014-10-17 12:31:18