Im adding every 2 posts in a div, but i also want to get the first post in a different div like this:
<div class="first">
<h2>Post title</h2>
</div>
<div>
<h2>Post title</h2>
<h2>Post title</h2>
</div>
<div>
<h2>Post title</h2>
<h2>Post title</h2>
</div>
Here is my code:
<?php
$count = 5;
$args = array(
'cat' => $mag_cat,
'post_type' => 'post',
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => $count
);
$posts = get_posts( $args ); ?>
<?php foreach ( array_chunk ( $posts, 2, true ) as $posts) :
if ( $posts == 0 ) {
echo '<div class="first">';
} else {
echo '<div>';
}
foreach( $posts as $post ) : setup_postdata($post); ?>
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php endforeach; ?>
</div>
The class .first does not seem to print, what I'm a doing wrong?