2017-08-15 51 views
0

在Visual Composer中有一個名爲Progress Bar的內置插件。我想創建一個自己風格的自定義進度條。如何在visual composer中爲自定義進度條插件創建簡碼?

我的自定義進度欄插件代碼:

<?php 

    // About Us 2 addons 
    vc_map(array(
     'name'   => __('About Us & Progress Bar', 'f_triangle'), 
     'base'   => 'abt_us_progress_bar', 
     "category"  => __("F Triangle", "f_triangle"), 
     'description' => __('', 'f_triangle'), 
     'params'  => array(
     array(
      'type'   => 'param_group', 
      'heading'  => __('Values', 'f_triangle'), 
      'param_name' => 'values', 
      'description' => __('Enter values for graph - value, title and color.', 'f_triangle'), 
      'group'  => __('Progress Bar', 'f_triangle'), 
      'value'  => urlencode(json_encode(array(
       array(
        'label' => __('Design', 'f_triangle'), 
        'value' => '35', 
       ), 
       array(
        'label' => __('HTML', 'f_triangle'), 
        'value' => '80', 
       ), 
       array(
        'label' => __('PHP', 'f_triangle'), 
        'value' => '60', 
       ), 
      ))), 
      'params' => array(
       array(
        'type'   => 'textfield', 
        'heading'  => __('Label', 'f_triangle'), 
        'param_name' => 'label', 
        'description' => __('Enter text used as title of bar.', 'f_triangle'), 
        'admin_label' => true, 
       ), 
       array(
        'type'   => 'textfield', 
        'heading'  => __('Value', 'f_triangle'), 
        'param_name' => 'value', 
        'description' => __('Enter value of bar.', 'f_triangle'), 
        'admin_label' => true, 
       ), 

      ), 
     ), 
    ) 
    )); 


?> 

我的HTML代碼:

<div class="col-sm-5 wow fadeInRight" data-wow-duration="1000ms" data-wow-delay="300ms"> 
    <div class="our-skills"> 
     <h2 class="bold">Our Skills</h2> 
     <div class="single-skill"> 
      <h3>Design</h3> 
      <div class="progress"> 
       <div class="progress-bar progress-bar-primary six-sec-ease-in-out" role="progressbar" data-transition="35">35%</div> 
      </div> 
     </div> 
     <div class="single-skill"> 
      <h3>HTML</h3> 
      <div class="progress"> 
       <div class="progress-bar progress-bar-primary six-sec-ease-in-out" role="progressbar" data-transition="80">80%</div> 
      </div> 
     </div> 
     <div class="single-skill"> 
      <h3>PHP</h3> 
      <div class="progress"> 
       <div class="progress-bar progress-bar-primary six-sec-ease-in-out" role="progressbar" data-transition="60">60%</div> 
      </div> 
     </div> 
    </div> 
</div> 

我的自定義進度欄插件工作在WordPress後臺編輯不錯,但我不明白,我怎麼能爲此插件創建簡碼以將其與我的HTML集成。這就是爲什麼我無法在前端顯示它。那麼,我如何爲這個插件創建簡碼呢?

回答

0

您必須在函數中使用add_shortcode掛鉤添加簡碼功能 https://codex.wordpress.org/Function_Reference/add_shortcode

和VC地圖參數添加簡碼的基礎參數,還可以添加簡碼屬性的參數數組 https://wpbakery.atlassian.net/wiki/spaces/VC/pages/524332/vc+map

例如,你有你的自己帶foo屬性的短碼bartag

// [bartag foo="foo-value"] 
add_shortcode('bartag', 'bartag_func'); 
function bartag_func($atts) { 
    extract(shortcode_atts(array(
     'foo' => 'something' 
    ), $atts)); 

    return "foo = {$foo}"; 
} 

vc_map(array(
     "name" => __("Bar tag test", "my-text-domain"), 
     "base" => "bartag", 
     "class" => "", 
     "category" => __("Content", "my-text-domain"), 
     'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'), 
     'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'), 
     "params" => array(
     array(
      "type" => "textfield", 
      "holder" => "div", 
      "class" => "", 
      "heading" => __("Text", "my-text-domain"), 
      "param_name" => "foo", 
      "value" => __("Default param value", "my-text-domain"), 
      "description" => __("Description for foo param.", "my-text-domain") 
     ) 
    ) 
    ));