Replies: 0
I have a shortcode for displaying REST posts and i would like to use the array_chunk function to split into new rows at x number of posts. My code below works fine in pages, posts and in the sidebar. However, since this isn’t a return; the code causes the main div to break out of the text widget and pushes the widget title below it.
Is there a way to return the output so this can be used effectively in the sidebar?
if( !empty( $posts ) ) {
echo "<div class='mrp-container'>\n";
foreach (array_chunk($posts, $a['columns']) as $post) {
echo "<div class='mrp-row'>\n";
foreach ( $post as $post ) {
// Make JSON date human readable
$jsondate = new DateTime( $post->date );
$humandate = $jsondate->format("F d, Y");
echo '<div class="single-mrp-post'.$mrpcolumns.'">' . '<a href="' . $post->link. '" title="'. $post->title->rendered .
PHP_EOL . PHP_EOL. strip_tags($post->excerpt->rendered) .' "><img src="'. $post->swp_thumbnail .'"/><h4 class="mrp-post-title">'. $post->title->rendered . '</h4></a><p class="mrp-post-date">'.$humandate."</p></div>\n";
}
echo "</div>\n";
}
echo "</div>\n";
}