2014-10-17 69 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