In my query, I'm gathering 6 posts and displaying them into an unordered list. Here's the code I'm using:
$args = array(
'post_parent' => $page_id->ID,
'showposts' => 6,
'post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC'
);
$subpages = new WP_query($args);
if ($subpages->have_posts()) :
while ($subpages->have_posts()) : $subpages->the_post();
$output .= '<li><a href="'.get_permalink().'" class="'.$page_id->post_name.'-link"><div class="'.$page_id->post_name.'-info"><div class="'.$page_id->post_name.'-img">'.get_the_post_thumbnail($page->ID,'icons').'</div><h2>'.get_the_title().'</h2>
<p class="'.$page_id->post_name.'-excerpt">'.get_the_excerpt().'</p>
</div></a></li>';
endwhile;
endif;
I'd like to breakup the and show three posts, then insert a different div, then continue the loop. The html outcome would look similar to:
<ul>
<li>Post1</li>
<li>Post2</li>
<li>Post3</li>
</ul>
<div class="notice">Some text goes here</div>
<ul>
<li>Post4</li>
<li>Post5</li>
<li>Post6</li>
</ul>
EDIT I got this working with the suggestions from @Rarst. Here's my updated code:
$args = array(
'post_parent' => $page_id->ID,
'showposts' => 6,
'post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC'
);
$subpages = new WP_query($args);
if ($subpages->have_posts()) :
while ($subpages->have_posts()) : $subpages->the_post();
$output .= '<li><a href="'.get_permalink().'" class="'.$page_id->post_name.'-link"><div class="'.$page_id->post_name.'-info"><div class="'.$page_id->post_name.'-img">'.get_the_post_thumbnail($page->ID,'icons').'</div><h2>'.get_the_title().'</h2>
<p class="'.$page_id->post_name.'-excerpt">'.get_the_excerpt().'</p>
</div></a></li>';
if (2 == $subpages->current_post):
$output .= '</ul>';
$output .= 'test';
$output .= '<ul class="'.$page_id->post_name.'">';
endif;
endwhile;
endif;