2014-07-08 2 views
0

저는 Wordpress를 처음 접했을뿐 아니라 지금까지 대부분의 문제를 직접 해결할 수있었습니다.Wordpress - 상위 및 하위 카테고리를 표시하는 맞춤 게시물 유형

맞춤 게시 유형이 있습니다. 전화 번호는 Machines입니다. 그리고 그 기계에는 Machine_type이라는 범주가 있습니다. 그리고 Scissor Lifts이라는 컴퓨터 유형을 만든 다음 electric scissor lifts이라는이라는 다른 컴퓨터 유형을 만들었다 고 가정 해보십시오.

이 정보를 단일 게시 페이지에 표시하고 싶습니다. electric scissor lifts 페이지에서 Machines - Scissor Lifts - Electric Scissor Lifts와 같은 breadcrumbs를 표시하고 싶습니다. 그러나 이것은 거의 불가능한 것처럼 보입니다! 나는 많은 다른 자습서를 사용하여 시도했다, 그러나 나는 항상 표시 할 실제적인 2 개의 종류없이 Machines - - - Final machine name를 표시 한 것을 보인다!

카테고리 및 하위 카테고리에 대한 간단한 inbuilt 호출이 없다는 것은 일종의 미친 것처럼 보입니다! 나는 이것을 사용하고 있었다 :

<?php 
    $terms = get_the_terms($post->ID , 'machine_type'); 
    foreach ($terms as $term) { 
     $term_link = get_term_link($term, 'machine_type'); 
     if(is_wp_error($term_link)) 
      continue; 
     echo '<p>Machine Type: <a href="' . $term_link . '">' . $term->name . '</a></p>'; 
    } 
?> 

그러나 이것은 분명히 모든 정보를 덤프하고 부모와 자식 카테고리를 훌륭하게 구분할 방법이 없다.

편집 :이 문제에 대한 업데이트

: 나는 마침내 그것이 바로 문제를 다루는 것 같아 몇 가지 코드를 발견했습니다, 무엇을 출력하는 것은 꽤 괜찮 그러나

<?php 
// get top level terms 
$parents = get_terms('machine_type', array('parent' => 0)); 
// get post categories 
$categories = get_the_terms($post->ID, 'machine_type'); 
// output top level cats and their children 
foreach($parents as $parent): 
// output parent name and link 
echo '<a href="' . get_term_link($parent) . '">' . $parent->name . '</a>: '; 
// initialize array to hold child links 
$links = array(); 
foreach($categories as $category): 
    if($parent->term_id == $category->parent): 
     // put link in array 
     $links[] = '<a href="' . get_term_link($category) . '">' . $category->name .  '</a>'; 
    endif; 
endforeach; 
// join and output links with separator 
echo join(', ', $links); 
endforeach; 

?> 

을하지 않습니다 . 예를 들어, Boom Lift 및 Articulated Electric Boom Lift로 분류 된 기계의 경우 "Boom lift : 굴절 식 붐 (전기) Scissor lift : 거미 리프트 :"

이 기계에는 적용 할 수없는 다른 2 가지 범주에 있습니다. 어떤 아이디어?

답변

0

이 요

<?php 

    /********************** List out the parent and child inside parent ***/ 
    $taxonomyName = "your_taxonomy"; 
    $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); 
    if ($term->parent == 1) { 
    wp_list_categories('taxonomy=your_taxonomy&depth=1&show_count=0 
    &title_li=&child_of=' . $term->term_id); 

    } else { 

    wp_list_categories('taxonomy=your_taxonomy&show_count=0 
    &title_li=&child_of=' . $term->parent); 
    } 
    ?> 
3
$wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>0)); 
foreach($wcatTerms as $wcatTerm) : 
    echo $wcatTerm->name; 
    $wsubargs = array('hierarchical'=>1,'show_option_none'=>'','hide_empty'=>0,'parent'=>$wcatTerm->term_id,'taxonomy'=>'product_cat'); 
    $wsubcats = get_categories($wsubargs); 
    foreach ($wsubcats as $wsc): 
     echo $wsc->name; 
    endforeach; 
endforeach; 

사용 범주 이름 및 제품 이름이 그것의 화면이 수준을 도움이 될 수 있습니다.

+0

안녕하세요 당신의 답변을 좋아하고 카테고리 이름을 표시해야합니다. 내가 하위 카테고리의 게시물을 표시 할 수 있도록 답변을 편집하십시오. 감사합니다. – dh47

관련 문제