我正在尝试使用Visual Composer扩展插件扩展客户端的页面后端。我一直按照这里给出的说明进行操作:http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial。
该插件显示在WP后端,并显示了我像这样创建的字段:
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"param_name" => "fourth_quote",
"value" => __("", 'vc_extend'),
"description" => __('Fourth testimonial quote', 'vc_extend')
)
但是,我不明白以后应该如何访问"fourth_quote":
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;
}
但是,即使存储了内容,这也不会输出任何内容。
如何访问用户在后端创建的内容,以便能够基于该内容呈现页面?如何获取变量?
从 http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial:
此列表表示简码标签作为基本和参数列表,它将 可以使用构造函数js_composer设置窗体进行编辑。
您必须将 fourth_quote
属性添加到简码中.
例如:
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;
}