0
我正在尋找一個短代碼進度條,需要一個百分比來確定它的'進度'。但是,我從另一段短代碼中獲得了我的百分比。如何嵌套2個第三方WordPress短代碼
當我嵌套兩個短代碼時,它們失敗。有人能幫助我嗎? 下面是插件的短代碼文件中的兩段代碼,第一個是進度條...
function fruitful_pbar_shortcode ($atts, $content = null) {
$out = $type = $class = '';
extract(shortcode_atts(array(
'id' => 'ffs-pbar-' . rand(1, 100),
'type' => '',
'active' => false,
'stripped' => false
), $atts));
if (!empty($id)) { $id = sanitize_html_class($id); }
if (!empty($type)) { $type = sanitize_html_class($type); }
if (!empty($active)) { $active = sanitize_html_class($active); }
if (!empty($stripped)) { $stripped = sanitize_html_class($stripped); }
$class .= $type;
if ($stripped) { $class .= ' progress-striped'; }
if ($active) { $class .= ' active'; }
$out .= '<div id="'.$id.'" class="progress '.$class.'">';
$out .= fruitful_sh_esc_content_pbr(do_shortcode($content));
$out .= '</div>';
$out .= '<div class="clearfix"></div>';
return $out;
}
add_shortcode ("fruitful_pbar", "fruitful_pbar_shortcode");
function fruitful_bar_shortcode ($atts, $content = null) {
$type = $width = '';
extract(shortcode_atts(array(
'type' => '',
'width' => '60%'
), $atts));
if (!empty($type)) { $type = sanitize_html_class($type); }
if (!empty($width)) { $width = esc_attr($width); }
return '<div class="bar '.$type.'" style="width: '.do_shortcode($width).';"></div>';
}
add_shortcode('fruitful_bar', 'fruitful_bar_shortcode', 99);
和第二(即進度條後放置)是Get個功能......
if(!function_exists('show_specific_product_quantity')) {
function show_specific_product_quantity($atts) {
// Shortcode Attributes
$atts = shortcode_atts(
array(
'id' => '', // Product ID argument
),
$atts,
'product_qty'
);
if(empty($atts['id'])) return;
$stock_quantity = 0;
$product_obj = wc_get_product(intval($atts['id']));
$stock_quantity = ((12000 - $product_obj->get_stock_quantity())/12000) * 100;
if($stock_quantity > 0) return $stock_quantity;
}
add_shortcode('product_qty', 'show_specific_product_quantity');
}
,下面將我使用的簡碼...
[fruitful_pbar][fruitful_bar type="progress-bar-info" width=" [product_qty id="4278"]% " stripped="true"][/fruitful_bar][/fruitful_pbar]
正如你所看到的 - 我使用簡碼內的短代碼來創建我需要什麼。 在此先感謝! :-)