dongqiang5865 2014-11-12 18:58
浏览 46
已采纳

如何在Visual Composer扩展的WordPress插件中访问变量?

I'm trying to extend my client's page backend with Visual Composer extended plugin. I've been following instructions given here: http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial.

The plugin shows at the WP backend and the fields I have created like this are shown:

array(
    "type" => "textfield",
    "holder" => "div",
    "class" => "",
    "param_name" => "fourth_quote",
    "value" => __("", 'vc_extend'),
    "description" => __('Fourth testimonial quote', 'vc_extend')
)

However, I don't understand how I'm supposed to access the 'fourth_quote' later on:

public function renderMyBartag( $atts, $content = null) {
  extract( shortcode_atts( array(
    'faa' => 'something',
    'color' => '#FF0000'
  ), $atts ) );

  $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content

  $output = '<div>{$fourth_quote}</div>';
  error_log(date('[ d.m.Y H:i:s ] ') . $output . PHP_EOL, 3, "my-errors.log");
  return $output;
}

This, however doesn't output anything even there is content stored.

How do I access the content user have created at the backend so I'd be able to render the page based on that? How do I get the variables?

  • 写回答

1条回答 默认 最新

  • dongzaobei0942 2014-11-12 20:28
    关注

    From http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial:

    This list represents shortcode tag as base and params list which will be editable with settings form inside js_composer constructor.

    You must add the fourth_quote attribute to the shortcode.
    For example:

    public function renderMyBartag( $atts, $content = null) {
    
        # Also, avoid using extract()
        # http://stackoverflow.com/questions/829407/what-is-so-wrong-with-extract
        # http://codex.wordpress.org/Shortcode_API
    
        $a = shortcode_atts( array(
            'faa'          => 'something',
            'color'        => '#FF0000',
            'fourth_quote' => false, // just a default value
        ), $atts );
    
        $content = wpb_js_remove_wpautop($content, true);
    
        $output = $a['fourth_quote'];
    
        error_log(date('[ d.m.Y H:i:s ] ') . $output . PHP_EOL, 3, "my-errors.log");
    
        return $output;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置