How do I split the values within a custom post type loop so that the title is in the first loop which outputs in the first DIV and the content is in the second loop outputting in the second DIV? Two loops may not be the best way to do, I don’t know. Somebody mentioned to me about one loop then storing in a string and then splitting the string. I have no idea how to do this either.
I also need a new row to begin once the number of posts reach 5.
Here’s my PHP loop…
<?php
$custom_query = new WP_Query( $custom_args );
query_posts(array( 'post_type' => array('team')) );
if ( $custom_query->have_posts() ) :
/* Start my loop */
while ( $custom_query->have_posts() ) : $custom_query->the_post();
echo "<div>". the_title(); . "</div>";
echo "<div>". the_content(); . "</div>";
endwhile;
endif;
?>
The HTML output i’m looking for as follows…
<div class"row">
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
</div>
<div class"row">
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
</div>
<div class"row">
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
<div class="container">
<div class="title chris"></div>
<div class="title darren"></div>
<div class="title ryan"></div>
<div class="title john"></div>
<div class="title emma"></div>
</div>
</div>
Pseudo Code…
$team; // array
$avatar = '';
$memberinfo = '';
foreach ($team as $member){
$avatar .= '<div>'. $member->avatar .'</div>';
$memberinfo .= '<div class="content">'. $member->memberinfo .'</div>';
if($newRow){
echo $avatar;
echo $memberinfo;
}
}
can you plz try this code.
it will give out put see below.