2017-10-28 1 views
0

안녕하세요 저는 맞춤 게시물 유형에 대한 Wordpress 페이지 템플릿을 만들고 있습니다. 포스트 유형은 플러그인을 통해 등록되고 작동하며 사용자 정의 분류 체계도 연관되어 있습니다.맞춤 분류 표시 하위 탭의 하위 항목

맞춤 분류의 각 상위 항목을 부트 스트랩 탭에 표시하고 있습니다.

내가해야 할 일은 탭 창에 하위 항목을 표시 한 다음 그 아래에 게시물 제목을 표시하는 것입니다. 계층 구조로이 같은

뭔가 : 지금까지 (내가 자식 항목을 표시 할 필요가 어디 표시 한)

TAB TITLE (parent) - done 
-- SECTION TITLE (child) 
-- -- POST TITLE 
-- -- POST TITLE 
-- SECTION TITLE (child) 
-- -- POST TITLE 
-- -- POST TITLE 


코드 : 어떤 도움이 많이 감사

<?php 

/** 
* Template Name: Agreement Index Page 
* 
* @package WordPress 
* @subpackage Twenty_Fourteen 
* @since Twenty Fourteen 1.0 
*/ 

get_header(); 

// Get list of 'categories' for tabs --> 
$args = array(
'hide_empty' => false, 
'parent' => 0 
); 

$sections = get_terms('agreement-section', $args); 
?> 

<div class="row"> 
<div class="col-md-12"> 
<h1 class="display-2 text-center"><?php the_title(); ?></h1> 
    <?php 
    while (have_posts()) : the_post(); 
     the_content(); 
    endwhile; ?> 

    <ul class="nav nav-tabs nav-fill" id="myTab" role="tablist"> 

     <!-- Create the tabs --> 
     <?php 
     // Use counter so that 'active' class is only applied to first tab 
     $counter = 0; 
     foreach ($sections as $section) { ?> 

      <li class="nav-item"> 
       <a class="nav-link <?= ($counter == 0) ? 'active' : '' ?>" id="<?php echo $section->slug;?>-tab" data-toggle="tab" href="#<?php echo $section->slug; ?>" role="tab" aria-controls="<?php echo $section->slug;?>" aria-selected="<?= ($counter == 0) ? 'true' : 'false' ?>"><?php echo $section->name; ?></a> 
      </li> 

     <?php $counter++; } ?> 

    </ul> 

    <div class="tab-content" id="nav-tabContent"> 
    <!-- Get the content for each tab --> 
    <?php 
    $counter2 = 0; 
    foreach ($sections as $section) { ?> 

     <div class="tab-pane container-fluid fade <?= ($counter2 == 0) ? 'show active' : '' ?>" id="<?php echo $section->slug; ?>" role="tabpanel" aria-labelledby="<?php echo $section->slug; ?>-tab"> 
      <div class="row"> 
       <?php 
        $args = array(
         'post_type' => 'agreement', 
         'tax_query' => array(
          array(
           'taxonomy' => $section->taxonomy, 
           'field' => $section->slug, 
           'terms' => $section->term_id 
          ) 
         ) 
        ); 

        $loop = new WP_Query($args); 

        ?> 

        <div class="col-md-6" id="<?php echo $section->slug . '-clauses' ?>"> 

          <?php   
           if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?> 

            <?php 
            //Do something if a specific array value exists within a post 
            $term_list = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all")); 

            foreach($term_list as $term_single) { ?> 
              <h4><?php echo $term_single->name; ?></h4> 
              <a class="col-md-12" href="  <?php echo the_permalink();?>"><?php echo the_title(); ?></a>           
            <?php } ?> 

          <?php endwhile; endif; wp_reset_query(); ?> 



</div> 
      </div> <!-- end row --> 

     </div> <!-- end tab-pane --> 
     <?php $counter2++; } ?> 
    </div> <!-- end tab-content --> 

</div> <!-- end col --> 
</div> <!-- end row --> 

<!-- end content --> 

. 상위 범주의

크리스

+0

섹션 제목 (아이) 상위 범주의 디스플레이 하위 범주를 의미? –

+0

예 - 실제로 분류는 있지만 부모의 예 하위는 내가 찾고있는 것입니다. –

+0

업데이트 : 게시물을 가져 오는 쿼리가 추가되었습니다. foreach 루프를 사용하지만'$ term_single-> name'이 나에게주는 자식 제목이 아니라 부모 title을 가져야합니다. –

답변

0

디스플레이 하위 카테고리

<?php 

/** 
* Template Name: Agreement Index Page 
* 
* @package WordPress 
* @subpackage Twenty_Fourteen 
* @since Twenty Fourteen 1.0 
*/ 

get_header(); 

// Get list of 'categories' for tabs --> 
$args = array(
'hide_empty' => false, 
'parent' => 0 
); 

$sections = get_terms('agreement-section', $args); 
?> 

<div class="row"> 
<div class="col-md-12"> 
<h1 class="display-2 text-center"><?php the_title(); ?></h1> 
    <?php 
    while (have_posts()) : the_post(); 
     the_content(); 
    endwhile; ?> 

    <ul class="nav nav-tabs nav-fill" id="myTab" role="tablist"> 

     <!-- Create the tabs --> 
     <?php 
     // Use counter so that 'active' class is only applied to first tab 
     $counter = 0; 
     foreach ($sections as $section) { ?> 

      <li class="nav-item"> 
       <a class="nav-link <?= ($counter == 0) ? 'active' : '' ?>" id="<?php echo $section->slug;?>-tab" data-toggle="tab" href="#<?php echo $section->slug; ?>" role="tab" aria-controls="<?php echo $section->slug;?>" aria-selected="<?= ($counter == 0) ? 'true' : 'false' ?>"><?php echo $section->name; ?></a> 
      </li> 

     <?php $counter++; } ?> 

    </ul> 

    <div class="tab-content" id="nav-tabContent"> 
    <!-- Get the content for each tab --> 
    <?php 
    $counter2 = 0; 
    foreach ($sections as $section) { ?> 

     <div class="tab-pane container-fluid fade <?= ($counter2 == 0) ? 'show active' : '' ?>" id="<?php echo $section->slug; ?>" role="tabpanel" aria-labelledby="<?php echo $section->slug; ?>-tab"> 
      <div class="row"> 
       <?php 
        $args = array(
         'post_type' => 'agreement', 
         'tax_query' => array(
          array(
           'taxonomy' => $section->taxonomy, 
           'field' => $section->slug, 
           'terms' => $section->term_id 
          ) 
         ) 
        ); 

        $loop = new WP_Query($args); 

        ?> 

        <div class="col-md-6" id="<?php echo $section->slug . '-clauses' ?>"> 
          <?php   
           if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?> 
            <?php 
            //Do something if a specific array value exists within a post 
            $term_list = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all")); 
            ?> 
            <h4> 
            <?php 
            foreach($term_list as $term_single) { 
             $category_children = get_terms($destination_category_taxonomy, array(
              'parent' => $term_single->term_id, 
              'hide_empty' => false 
              )); 
             $category_children_count = count($category_children); 

             if($category_children_count>0) 
             { 
              $category_children_name_array = array(); 
              foreach($category_children as $category_children_single) { 
               $category_children_name_array[]=$category_children_single->name; 
              } 

              //display child category of parent category 
              echo implode(",",$category_children_name_array); 
             } 
             else 
             { 
              //display parent category 
              echo $term_single->name; 
             } 
            ?> 
            </h4> 
            <a class="col-md-12" href="<?php echo the_permalink();?>"><?php echo the_title(); ?></a>           
            <?php } ?> 
          <?php endwhile; endif; wp_reset_query(); ?> 
       </div> 
      </div> <!-- end row --> 

     </div> <!-- end tab-pane --> 
     <?php $counter2++; } ?> 
    </div> <!-- end tab-content --> 

</div> <!-- end col --> 
</div> <!-- end row --> 

<!-- end content --> 
관련 문제