2016-08-22 2 views
4

비슷한 프로젝트가 사이트를 상실한 최근에 충돌을 경험했기 때문에이 작업을 완료하는 데 플러그인을 사용하고 싶지 않습니다. 따라서이 기능을 기본으로 만들려고합니다.WooCommerce 드롭 다운 선택기의 브랜드 분류학 용어 목록

브랜드별로 제품을 선택하려면 제품 카테고리 페이지의 드롭 다운 목록이 필요합니다. 드롭 다운 목록에는 모든 브랜드가 표시됩니다. 하나를 선택하면 사이트는 브랜드에 할당 된 제품 만 표시합니다. 우리는 내 브랜드를 설정하고 각 제품에게 브랜드을 할당 한 WooCommerce 'Brands '분류를 사용하는 등 새로움, 가격, 인기

가 볼 수있는 내장 드롭 다운을 사용할 필요가 없습니다.

I는 모든 브랜드의 어레이와 다음 코드와 그 속성 볼 수있는 다음 출력

$brands = get_terms('brand'); 
print_r($brands); 

을 :

어레이 (

[0] => WP_Term 978 [taxonomy] => brand [description] => [parent] => 978 [이름] => 이마리 소마 츠케 [slug] => 이마리 sometsuke [term_group] => 0 [term_taxonomy_id] => > 0 [count] => 1 [필터] => raw)[term_id] => 982 [이름] => 쿠타니 [slug] => 쿠타니 [term_group] => 0 [term_taxonomy_id] => 982 [taxonomy] => 브랜드 [description] ]]> = [부모] => 0 [count] => 2 [필터] => raw)

[2] => WP_Term 개체 ([term_id] => 977 [name] => Kutani Shoza [slug] = kutani-shoza [term_group] => 0 [term_taxonomy_id] => 977 [taxonomy] => 브랜드 [description] => [parent] => 0 [count] => 4 [filter] => raw)

[term_group] => 0 [term_taxonomy_id] => 979 [taxonomy] => 브랜드 [description] :

[3] => WP_Term 오브젝트 ([term_id] => 979 [name] => Kutani Tokkuri [slug] ] => [부모] => 0 [count] => 2 [필터] => raw)Nishikawa Sukenobu [slug] => nishikawa-sukenobu [term_group] => 0 [term_taxonomy_id] => 985 [taxonomy] => WP_Term 객체 ([term_id] => 985 [name] => [용어 설명] => 984 [이름] =>이 신수이 [브랜드] [설명] => [부모] => 0 [개수] => 1 [필터] => 가공되지 않음)

[ [설명] => [부모] => 0 [개수] => 2 [필터] => 미성년자 => 0 [용어집] => 0 [term_taxonomy_id] => 016] [이름] => 976 [이름] => Takeji Asano [slug] => takeji-asano [term_group] => 0 [term_taxonomy_id] => 976 [taxonomy] => 브랜드 [description] => [parent] => 0 [count] => 2 [filter] => raw)

[8] => 980 [tax_omy] => 980 [tax_omy] => 980 [이름] => 980 [이름] => 토슈 사이 샤락 [용어집] => 브랜드 [설명] => [부모] => 0 만들 수) 목록 => 3 [필터] => 원시)

하나의 메뉴를 구성 가겠어요 방법)

(선택 [계산] 이? 는 나는 내가 시작했습니다 같은 프레임 워크 뭔가있을 것입니다 상상 :이 용어는 객체 (WP_Term 개체)의 배열입니다 당신이 볼 수 있듯이

<?php 
$brands = get_terms('brand'); 
//print_r($brands); 
?> 

<select name="orderby" class="orderby"> 
    <?php foreach ($brands as ???) : ?> 
     <option value="<?php echo esc_attr($???); ?>" <?php selected($orderby, $???); ?>><?php echo esc_html($???); ?></option> 
    <?php endforeach; ?> 
</select> 

답변

2

을, 당신은 객체 구문을 사용해야합니다 루프에서 용어의 각 속성에 대해,이 방법 :

<?php 

    $brands = get_terms('brand', array(
     'orderby' => 'name' // orderby arguments ('name', 'slug','term_group', 'term_id', 'id', 'description') 
    )); 
    //print_r($brands); 

?> 
<select name="orderby" class="orderby"> 
    <?php 
     foreach ($brands as $key => $brand) : 
      $brand_id = $brand->term_id; 
      $brand_name = $brand->name; 
      $brand_slug = $brand->slug; 
      $brand_term_group = $brand->term_group; 
      $brand_term_taxonomy = $brand->term_taxonomy_id; 
      $brand_taxonomy = $brand->taxonomy; 
      $brand_description = $brand->description; 
      $brand_parent = $brand->parent; 
      $brand_count = $brand->count; 
      $brand_filter = $brand->filter; 

      $number = $key+1; 
      $option = 'option-' . $number; 
    ?> 
     <option value="<?php echo $option; ?>"><?php echo $brand->name; ?></option> 
    <?php endforeach; ?> 
</select> 

이 코드는 테스트 및

를 작동