2016-06-22 3 views
1

부모 카테고리 이름 만 표시하고 싶지 않으며 어떤 제품이나 게시물에도 사용되지 않은 도 표시하고 싶습니다. 부모 맞춤 카테고리 목록 만 있으면됩니다.상위 맞춤 분류 분류 이름 만 표시 하시겠습니까?

은 내가 get_terms, wp_list_categories 기능뿐만 아니라

이 내 코드는이 아이를 보여주는 시도합니다.

<?php 
    require_once('connection.php'); 
    $taxonomy  = 'product_cat'; 
    $orderby  = 'parent'; 
    $show_count = 0;  // 1 for yes, 0 for no 
    $pad_counts = 0;  // 1 for yes, 0 for no 
    $hierarchical = 0;  // 1 for yes, 0 for no 
    $title  = ''; 
    $empty  = 0; 

    $args = array(
    'taxonomy'  => $taxonomy, 
    'orderby'  => $orderby, 
    'show_count' => $show_count, 
    'pad_counts' => $pad_counts, 
    'childless'    => false, 
    'child_of'    => 0, 
    'title_li'  => $title, 
    'hide_empty' => $empty, 
    'hierarchical'=>1 
    //'hierarchical=0&depth=1' 
); 

    $rrr=wp_list_categories($args); 
    print_r($rrr); 
?> 

자녀를 표시하고 있지만 상위 카테고리 이름 만 필요합니다.

난 Product_cat은 woocommerce 카테고리이다 사용 제가 get_terms 함께 사용될 때 그것은 널 배열 소정있다.

나는이 방법처럼 사용할하지만 product_cat는 get_terms

<?php 
$parent_cat_arg = array('hide_empty' => false, 'parent' => 0); 
$parent_cat = get_terms('product_cat',$parent_cat_arg); 

foreach ($parent_cat as $catVal) { 
    /*some code*/ 
} 
?> 

또한 내가 필요한 설명이 첨부 이미지보기 작동하지 않습니다.

enter image description here

+0

당신이 시도해 봤어입니다 설정보십시오? – Milap

+0

네, 해보았습니다. –

답변

1

parent0

$taxonomy  = 'product_cat'; 
    $orderby  = 'parent'; 
    $show_count = 0;  // 1 for yes, 0 for no 
    $pad_counts = 0;  // 1 for yes, 0 for no 
    $hierarchical = 0;  // 1 for yes, 0 for no 
    $title  = ''; 
    $empty  = 0; 

    $args = array(
    'taxonomy'  => $taxonomy, 
    'orderby'  => $orderby, 
    'show_count' => $show_count, 
    'pad_counts' => $pad_counts, 
    'childless'    => 0, 
    'child_of'    => 0, 
    'title_li'  => $title, 
    'hide_empty' => $empty, 
    'parent'=>0, 

); 

    $rrr=wp_list_categories($args); 
    print_r($rrr); 
+0

작동하지 않습니다. product_cat은 woocommerce 카테고리이며 wp_list_categories, get_terms, get_categories에서는 작동하지 않습니다. –

+0

저를 위해 일하고 있습니다 –

+0

당신은 woocommerce 종류를 사용하고 있습니까? –

1

사용이 코드는 부모 카테고리 이름 당신이 사용자 정의 포스트 유형 분류의 이름을 변경할 수 있습니다

<?php 
     $terms = get_terms('category', array('hide_empty' => false, 'parent' => 0)); 
     $terms2 = $terms; 
     for ($i = 0; $i < count($terms); $i++) { 
      $child = get_terms('category', array('hide_empty' => false, 'parent' => $terms[$i]->term_id)); 
      $terms2[$i]->child = $child; 
     } 

     for ($s = (count($terms2) - 1); $s >= 0; $s--) { 

      if (isset($terms2[$s]->child)) { 
       echo "<select name='parent_cat' class='dropdown' id='cat_" . $terms2[$s]->name . "'>"; 
       echo "<option selected='selected' value=''>" . $terms2[$s]->name . "</option>"; 
       for ($ch = 0; $ch < count($terms2[$s]->child); $ch++) { 
        echo "<option value='" . $terms2[$s]->child[$ch]->term_id . "'>" . $terms2[$s]->child[$ch]->name . "</option>"; 
       } 
       echo "</select>"; 
      } 
     } 
    ?> 

용어를 표시합니다. `0 = 계층 적 깊이 = 1`을 :

+0

작동하지 않습니다. –

관련 문제