SCENARIO: I inherited a WordPress site that uses the Thesis theme. I have Content Blocks installed, which I use to populate the right sidebar. I have a function that randomly picks up three post excerpts in the Books category. The excerpts contain iframes to book listings from Amazon.com. View on http://thebakingwizard.com/
PROBLEM: The posts are picking up randomly, as desired, but the iframes are outside of the layer structure in the function.
WHAT I HAVE DONE SO FAR:
- I understand that iframes should not be inside paragraph tags, so I used remove_filter( 'the_excerpt', 'wpautop' ); to remove the paragraph tags that Content Blocks create automatically. This did not change the situation.
- I changed the unordered list HTML to divs in case they were causing the problem. This did not work either.
I need the iframes to be inside the divs so I can line them up in one row.
THE FUNCTION
function RandomBook()
{
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 3,
'category_name' => 'Books',
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$string .= '<div id="AmazonListings">';
while ( $the_query->have_posts() )
{
$the_query->the_post();
$BookExcerpt = the_excerpt();
$string .= '<div class="BookExcerpt">'.$BookExcerpt.'</div>';
} // end while
$string .= '</div><!-- end Amazon book listings -->';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
} // 5/23/17 Nora added */
return $string;
} /* End Random post code from http://www.wpbeginner.com/wp-tutorials/how-to-display-random-posts-in-wordpress/<br />
5/11/17 Nora added */
add_shortcode('RandomBook','RandomBook');
add_filter('widget_text', 'do_shortcode');