2016-10-01 3 views
1

이것은 내 코드이며 두 번째 자식을 루프에 추가하려고합니다. 내가 어떻게 할 수 있는지 말해줘. 나는 워드 프레스에서 새롭다.워드 프레스 루프에서 특정 자식 클래스를 추가하는 방법

<?php 
     $args = array(
      'posts_per_page' => 3, 
      'post_type' => 'hosting_plan', 
      'order' => 'ASC' 
     ); 
     query_posts($args); 
     if (have_posts()) : while (have_posts()) : the_post(); 
    ?> 
     <div class="hostplbx /*here i want to add class on second child*/"> 
      <h3><?php the_field('plan_name'); ?></h3> 
      <div class="hostprice"> 
       <span class="hosprice"><b class="rs"><?php the_field('plan_price'); ?></b> per month</span> 
       <span class="plandetail"><?php the_field('tag_line'); ?></span> 
      </div> 

      <?php the_content(); ?> 

      </div> 
      <?php endwhile; ?> 
      <?php endif; ?> 

답변

0

당신은 간단한 반복자 변수를 사용할 수 있습니다 - 일부 샘플 코드는 템플릿에 적용 할 변경할 수 있습니다 :

$counter = 1; 

if (have_posts()) : while (have_posts()) : the_post(); 

    if($counter == 2) echo "<div class='second_child_class'>content goes here</div>"; 
    else echo "<div>content goes here</div>"; 

    $counter++; 

endwhile; endif; 
관련 문제