2013-06-05 4 views
0

분류 체계 하위 링크를 표시하는 데 도움이 될지 궁금한 점이 있습니다. 예를 들어, "study_type"의 사용자 지정 분류와 "보안"과 같은 범주가있는 "코스"의 사용자 정의 게시 유형이 있습니다. "professional"등. 현재 카테고리 제목과 설명을 정확하게 표시하고 있습니다. 카테고리로 분류되는 코스에 대한 퍼머 링크를 얻고 카테고리 설명 아래에 표시하는 방법을 알아야합니다. 도움이나 조언을 해주셔서 감사합니다. 다음은 나에게있다 코드 :목록 맞춤 분류학 아동용 링크

<?php 
//list terms in taxonomy 
$types[0] = 'study_type'; 

foreach ($types as $type) { 
$taxonomy = $type; 
$terms = get_terms($taxonomy, ''); 
if ($terms) { 
    foreach($terms as $term) { 
    echo '<h2>'.$term->name.'</h2>'; 
    echo '<p>' . $term->description . '</p>'; 
    //This is where the links should be 
} 
} 
} 
?> 

답변

0

사용 get_term_children

<?php 
//list terms in taxonomy 
$types[0] = 'study_type'; 

foreach ($types as $type) { 
$terms = get_terms($type, ''); 
if ($terms) { 
    foreach($terms as $term) { 
    echo '<h2>'.$term->name.'</h2>'; 
    echo '<p>' . $term->description . '</p>'; 
    //This is where the links should be 
    $termchildren = get_term_children($term->term_id, $type); 
    if($termchildren){ 
    echo '<ul>'; 
    foreach ($termchildren as $child) { 
    $term = get_term_by('id', $child, $taxonomy_name); 
    echo '<li><a href="' . get_term_link($term->name, $type) . '">' . $term->name . '</a></li>'; 
    } 
    echo '</ul>'; 
    } 
    } 
} 
} ?> 
+0

이 멋진 외모와 아마 잘하지만 내 링크 중 하나를 표시하지 않습니다. 그 'id'문자열을 대체해야합니까? 그렇다면 무엇을? 이 일을 도와 주셔서 다시 한 번 감사드립니다. – DevUps

+0

코드를 업데이트하여 기본적으로 분류 이름을 포함하지 않는 get_term_link()가 올바르게 작동합니다. –

+0

안녕하세요. 도움을 주셔서 감사하지만 불행히도 링크를 보여주지는 않지만 설명과 제목을 표시하고 있습니다. 당신이 생각할 수있는 다른 것은 없습니까? 감사. – DevUps