场景:我继承了一个使用论文主题的WordPress网站。我安装了内容块,用于填充右侧边栏。我有一个函数,可以随机选取图书类别中的三篇文章摘录。这些摘录包含了从Amazon上预订列表的iFrame。com。查看时间http://thebakingwizard.com/
问题:帖子是根据需要随机选取的,但iFrame在函数的层结构之外。
到目前为止我所做的:
我知道iframe不应该在段落标记中,所以我使用了remove\\u filter(\'the\\u extract\',\'wpautop\');删除内容块自动创建的段落标记。这并没有改变情况我需要将iFrame放在div内,以便将它们排成一行。
功能
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\');