2014-01-22 89 views
0

我用下面的短代碼來調用我的插件:[end_slider]更改寬度和高度WordPress的簡碼的jQuery插件

這是我在我的功能文件中的代碼:

function slider_func() { 
?> 
    <script> 
     jQuery(document).ready(function($) { 
       $('#banner-fade').bjqs({ 
        height: 350, 
        width: 980, 
        responsive: true 
       }); 
     }); 
    </script> 
    <?php 
} 

add_shortcode('end_slider', 'slider_func'); 

如何我可以創建一個函數來調整短代碼中插件的寬度和高度嗎?

的短代碼看起來是這樣的:[end_slider寬度=「980」 HEIGHT =「350」]

回答

1

根據該WordPress Shortcode API documentation,第一參數可用於接受短碼屬性。

您可以重新配置功能,像這樣:

function slider_func($atts) { 
    extract(shortcode_atts(array(
     'width' => '600', // default width 
     'height' => '400', // default height 
    ), $atts)); 
    ?> 
    <script> 
     jQuery(document).ready(function($) { 
       $('#banner-fade').bjqs({ 
        height: <?php echo (int) $height; ?>, 
        width: <?php echo (int) $width; ?>, 
        responsive: true 
       }); 
     }); 
    </script> 
    <?php 
} 
+0

太感謝你了雅各! – Breon