2017-11-20 9 views
0

Wordpress 루프 안에 두 가지를 조합해야합니다.루프의 다른 부분에 특정 카테고리의 레벨을 표시하십시오.

우선 모든 범주의 모든 2 차 범주 (예 : C1.1 및 C2.1)의 범주 이름을 표시하고 싶습니다.

그런 다음 두 번째 수준 카테고리 제목 아래에 표를 넣으 려합니다. 두 번째 수준 카테고리의 세 번째 수준 (예 : C1.1.1)만큼 많은 열을 가져야합니다. 각 열에는 세 번째 수준 카테고리의 모든 게시물을 표시하고 싶습니다.

카테고리 계층 :

C1 
— C1.1 
— — C1.1.1 
— — C1.1.2 
— — C1.1.3 
C2 
— C2.1 
— — C2.1.1 
— — C2.1.2 
... 

이것은 예이다

C1.1

+——————————+——————————+——————————+ 
| C1.1.1 | C1.1.2 | C1.1.3 | 
+——————————+——————————+——————————+ 
| Post | Post | Post | 
| Post | Post |   | 
|   | Post |   | 
+——————————+——————————+——————————+ 

C2.1

+——————————+——————————+ 
| C2.1.1 | C2.1.2 | 
+——————————+——————————+ 
| Post | Post | 
| Post | Post | 
| Post | Post | 
|   | Post | 
|   | Post | 
+——————————+——————————+ 

,745 ...

맞춤 템플릿 페이지에서이 작업을 수행 할 수 있습니까?

답변

0

이 시도

<?php 
 
//Get All Categories like Parent, parent of child, child of subchild (Level 0 , 1, 2) 
 
$taxonomy = 'category'; //Choose the taxonomy 
 
$terms = get_terms($taxonomy); //Get all the terms 
 

 
foreach ($terms as $term) { //Cycle through terms, one at a time 
 

 
    // Check and see if the term is a top-level parent. If so, display it. 
 
    $parent = $term->parent; 
 
    if ($parent=='0') { 
 

 
     $term_id = $term->term_id; //Define the term ID 
 
     $term_link = get_term_link($term, $taxonomy); //Get the link to the archive page for that term 
 
     $term_name = $term->name; 
 
     //Main Category 
 
     echo '<a class="ccats" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a><br/>'; 
 

 
     $childargs = array('parent' => $term_id); 
 
     $childcategories = get_categories($childargs); 
 
     foreach($childcategories as $childcategory) { 
 
      $childterm_id = $childcategory->term_id; 
 
      //Parent of Child Category 
 
      echo '<p>Category: <a href="' . get_category_link($childcategory->term_id) . '" title="' . sprintf(__("View all posts in %s"), $childcategory->name) . '" ' . '>' . $childcategory->name.'</a> </p> '; 
 

 
       $subchildargs = array('parent' => $childterm_id); 
 
       $subchildcategories = get_categories($subchildargs); 
 
       foreach($subchildcategories as $subchildcategory) { 
 
        //Parent of Child of Subchild Category 
 
        echo '<p>SubCategory: <a href="' . get_category_link($subchildcategory->term_id) . '" title="' . sprintf(__("View all posts in %s"), $subchildcategory->name) . '" ' . '>' . $subchildcategory->name.'</a> </p> '; 
 
        } 
 
      } 
 
     } 
 
} 
 
?>

+1

나는 테이블을 사용했다하지만했다! 고맙습니다! –

관련 문제