2012-09-13 2 views
0

나는이 같은 URL 구조를 가지고 상상 "www.domain.com/category/"코드는 카테고리의 모든 하위를 올바르게 표시하지만 "www.domain.com/category/subcategory/"에서는 하위 카테고리에 하위 태그가 없어 코드에 결과가 표시되지 않습니다. . 자식 페이지 일 때에도 최상위 범주의 자식 만 표시하도록 코드가 필요합니다.표시 아이들은

어떻게해야합니까? TIA.

답변

0
$ancestors = get_ancestors($cat-id, 'category'); 
$args=array(
    'child_of' => ($ancestors ? end($ancestors) : $cat-id), //If category has ancestors, use the top-most ancestor, otherwise, use the current category ID 
    'hide_empty' => 0, 
    'orderby' => 'name', 
    'order' => 'ASC' 
); 
$categories=get_categories($args); 
foreach($categories as $category) { 
    echo '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '>' . $category->name.'</a>'; } 
관련 문제