我在functions.php文件中插入了一个短代码。 shorcode是:
function multi_carousel_random_shortcode($ atts){ extract(shortcode_atts(array( ' post_type' => '转盘项&#39 ;, ),$ atts));
$q = new WP_Query(
array('posts_per_page' => -1, 'post_type' => $post_type)
);
$list = '
<script>
jQuery(document).ready(function() {
jQuery("#owl-demo-eleven").owlCarousel({
navigation: true,
navigationText: ["<i class=fa fa-angle-left></i>","<i class='fa fa-angle-right'></i>"],
});
});
</script>
<div id="owl-demo-eleven" class="owl-carousel owl-theme">
';
while($q->have_posts()) : $q->the_post();
$idd = get_the_ID();
$carousel_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'carousel-small' );
$list .= '
<div class="item"><img src="'.$carousel_img[0].'" alt="" /></div>
';
endwhile;
$list.= '
</div>
';
wp_reset_query();
return $list;
}
add_shortcode('multi_carousel_random', 'multi_carousel_random_shortcode');
一切都很好,但是&#39;图标代码&#39;在navigationText中产生错误。 你有解决问题的方法吗?
答案 0 :(得分:0)
navigationText: ["<i class=fa fa-angle-left></i>","<i class='fa fa-angle-right'></i>"],
未正确转义。
当你有'
定义的字符串时,只要有另一个'
没有定义字符串的结尾,你必须使用\'
来转义它,告诉它程序,这不是字符串的结尾。
应该是:
navigationText: ["<i class=\'fa fa-angle-left\'></i>","<i class=\'fa fa-angle-right\'></i>"],