I am trying to get the posts from evenementen. I only want 4 posts because my layout is a 2x2 column. This column has a special template for the top and bot. I want to show the 4 evenementen in this column but I don't want to change the layout if there are less.
In the PHP file I loop all the posts in evenementen and want to do add these in the specific columns.
PHP FILE
<?php
$args = array( 'posts_per_page' => 4, 'offset'=> 1, 'category' => 0 );
$myposts = get_posts( $args );
$count = 0;
foreach ( $myposts as $post ) : setup_postdata( $post );
$count++;
if ($count == 1) {
$title1 = the_title();
$date1 = the_date();
$link1 = the_permalink();
}
elseif ($count == 2) {
$title2 = the_title();
$date2 = the_date();
$link2 = the_permalink();
}
elseif ($count == 3) {
$title3 = the_title();
$date3 = the_date();
$link3 = the_permalink();
}
elseif ($count == 4) {
$title4 = the_title();
$date4 = the_date();
$link4 = the_permalink();
}
else {
}
endforeach;
?>
<div class="wrapper">
<div id="bigone">
<div class="wrapper">
<h4 class="push"><?php echo $title1; ?></h4>
<div id="one"> <p class="greytext"><?php echo $date1; ?></p></div>
<div id="two"> <p class="opmaak"><a href="<?php echo $link1; ?>">Evenementen</a></p></div>
</div>
</div>
<div id="bigtwo">
<div class="evenementenborder">
<div class="wrapper">
<h4 class="push"><?php echo $title2; ?></h4>
<div id="one"> <p><?php echo $date2; ?></p> </div>
<div id="two"> <p class="opmaak"><a href="<?php echo $link2; ?>">Evenementen</a> </p></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="evenementenfooter">
<div class="wrapper">
<div id="bigone">
<div class="wrapper">
<h4 class="push"><?php echo $title3; ?></h4>
<div id="one"> <p class="greytext"><?php echo $date3; ?></p></div>
<div id="two"> <p><a href="<?php echo $link3; ?>">Evenementen</a></p></div>
</div>
</div>
<div id="bigtwo">
<div class="evenementenborder">
<div class="wrapper">
<h4 class="push"><?php echo $title4; ?></h4>
<div id="one"> <p class="greytext"><?php echo $date4; ?></p> </div>
<div id="two"> <p><a href="<?php echo $link4; ?>">Evenementen</a> </p></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is the closest I got so far. But this does not put the text on the proper position and the hyperlink is also in the text.
I want to ask you guys: what is the best way to solve this? Or if I made a mistake in the code why it is not on the proper position?
I found out that informatie is directly placed on the page and the echo can't find the information because on that moment it is empty. I don't know how to solve this. Please post if you see what I am doing wrong.
i think its the buffering, Put in the beggining
ob_start();
And in the end of the document
ob_end_flush();
And try again. Check here for documentation about buffering