Array_Chunk issue in sidebar using shortcode
-
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"; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Array_Chunk issue in sidebar using shortcode’ is closed to new replies.