2017-06-22 7 views
0

私は、進行状況を決定するためにパーセンテージが必要なショートコードを使ってプログレスバーを作成しようとしています。しかし、私はショートコードの別の部分から私の割合を得ています。2つのサードパーティのWordpressショートコードを入れ子にする方法

2つのショートコードをネストすると、それらは失敗します。誰かが私を助けることができますか?以下 は...最初のプログレスバーがあり、取得率の関数である(プログレスバーの後に置かれている)

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); 

そして第二に...

プラグインのショートファイル内の2つのコードスニペットです
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] 

あなたが見ることができるように - 私は私が必要なものを作成するためにショートの内部でショートコードを使用しています。 ありがとうございます! :-)

答えて

0

最初のshortcodeの結果を1つの変数で取得し、2番目のshortcodeを属性として送信します。

関連する問題