为什么我的滑块快捷码显示在标题上方

时间:2022-02-10 作者:MR. shaikh__92

//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(),但当我最后添加整个滑块时,隐藏了任何类型的帮助,提前感谢:)

1 个回复
最合适的回答,由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;

相关推荐

更好地搜索WordPress.org插件?

我试图找到一些特定的手风琴插件(FAQ),但要以古腾堡积木的形式。上有一组“块启用”插件https://wordpress.org/plugins/browse/blocks/应该有一种简单的方法来完成这项任务。我做了很多实验,但没有一个结果是令人满意的。使用专业网站https://wpdirectory.net/;已尝试搜索(?mi)(^\\s*Plugin\\s+Name:.+accordion.+$) 实现不区分大小写的搜索accordion 插件名称中。但我无法搜索“块”插件,因为无法实现和功能: