//slider shortcode
function slider_shortcode($atts) {
extract( shortcode_atts( array(
\'id\' => \'\'), $atts));
$id = $id;
ob_start();?>
<div class="gallary">
<?php
// Check rows exists.
if( have_rows(\'slider\',$id) ):
// Loop through rows.
while( have_rows(\'slider\',$id) ) : the_row();
$slider_image = get_sub_field(\'slider_image\');
$slider_heading = get_sub_field(\'slider_heading\');
$slider_text = get_sub_field(\'slider_text\');
$slider_button = get_sub_field(\'slider_button\');
$slider_button_link = get_sub_field(\'slider_button_link\');?>
<div>
<div class="display">
<div class="text">
<h3><?php echo $slider_heading; ?></h1>
<p><?php echo $slider_text; ?></p>
<a class="shop_now" href="<?php echo $slider_button_link;?>" class="btn_slide"><?php echo $slider_button; ?></a>
</div>
<div class="image">
<img class="p_image" src="<?php echo $slider_image; ?>"/>
</div>
</div>
</div>
<?php
// End loop.
endwhile;
// No value.
else :
endif;
?>
</div>
<?php
}
add_shortcode(\'carousel\', \'slider_shortcode\');
//js
jQuery(document).ready(function($){
jQuery(".gallary").slick({
dots:true,
autoplay: true,
fade: true,
autoplaySpeed: 3000,
});
});
页面链接:
https://theelectronicstore.in/demo/我认为发生此错误的原因是ob\\u get\\u clean(),但当我最后添加整个滑块时,隐藏了任何类型的帮助,提前感谢:)
最合适的回答,由SO网友:Karolína Vyskočilová 整理而成
您需要从输出缓冲区返回值,如下所示:
//slider shortcode
function slider_shortcode($atts) {
extract( shortcode_atts( array(
\'id\' => \'\'), $atts));
$id = $id;
ob_start();?>
<div class="gallary">
<?php
// Check rows exists.
if( have_rows(\'slider\',$id) ):
// Loop through rows.
while( have_rows(\'slider\',$id) ) : the_row();
$slider_image = get_sub_field(\'slider_image\');
$slider_heading = get_sub_field(\'slider_heading\');
$slider_text = get_sub_field(\'slider_text\');
$slider_button = get_sub_field(\'slider_button\');
$slider_button_link = get_sub_field(\'slider_button_link\');?>
<div>
<div class="display">
<div class="text">
<h3><?php echo $slider_heading; ?></h1>
<p><?php echo $slider_text; ?></p>
<a class="shop_now" href="<?php echo $slider_button_link;?>" class="btn_slide"><?php echo $slider_button; ?></a>
</div>
<div class="image">
<img class="p_image" src="<?php echo $slider_image; ?>"/>
</div>
</div>
</div>
<?php
// End loop.
endwhile;
// No value.
else :
endif;
?>
</div>
<?php
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
add_shortcode(\'carousel\', \'slider_shortcode\');
我在函数的末尾添加了这些行:
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;