Wordpress 视觉作曲家;自定义元素赢得';t加载textarea_html/';内容';

Wordpress 视觉作曲家;自定义元素赢得';t加载textarea_html/';内容';,wordpress,Wordpress,目前正在使用WordPress 4.4.2,我正在开发一些定制的可视化Composer元素 然而,每当我想使用textarea_html参数(这样最终用户就可以使用wysiwyg编辑器)时,我似乎无法在呈现模板时获取它的内容 “titled_content_box.php”的内容 // called during vc_before_init function integrate_titled_content_box(){ register_titled_content_box();

目前正在使用WordPress 4.4.2,我正在开发一些定制的可视化Composer元素

然而,每当我想使用textarea_html参数(这样最终用户就可以使用wysiwyg编辑器)时,我似乎无法在呈现模板时获取它的内容

“titled_content_box.php”的内容

// called during vc_before_init
function integrate_titled_content_box(){
    register_titled_content_box();
    add_shortcode( 'titled_content_box', 'titled_content_box_func');
}

//Mapping of titled-contentbox
function register_titled_content_box(){
    vc_map( array(
        "name"              =>  __( "Content box with Title", "mytheme"),
        "base"              =>  "titled_content_box",
        "class"             =>  "",
        "category"          =>  "Content",
        "params"            =>  array(
            array(
                "type"          =>  "textfield",
                "holder"        =>  "div",
                "class"         =>  "",
                "heading"       =>  __( "Title", "mytheme"),
                "param_name"    =>  "title",
                "value"         =>  __("Box title", "mytheme"),
                "description"   =>  __("The title covering the content box", "mytheme")
            ),
            array(
                "type"          =>  "textarea_html",
                "holder"        =>  "div",
                "class"         =>  "",
                "heading"       =>  __( "Description", "mytheme"),
                "param_name"    =>  "content",
                "value"         =>  '<p>Placeholder</p>',
                "description"   =>  __("The content", "mytheme")
            )
        )
    ));
}

// Setting values where necessary and fetching the template
function titled_content_box_func( $atts ){
    extract( shortcode_atts( array(
        'title'      =>  'title',
        'content'    =>  'content'
    ), $atts) );

    return include_vc_template('titled_content_box.php', $atts);
}

add_action ( 'vc_before_init', 'integrate_titled_content_box');

由于这是一个项目,我在我的业余时间工作,我不能帮助,但感到恼火的一个功能不工作的文件。。。我所做的大多数搜索都只是将我的背部指向wpbakery的vc_map()知识库页面。。。任何指点都会很棒

将模板回调函数更新为:

function titled_content_box_func( $atts, $content ) {
    $atts = shortcode_atts( array(
        'title'      =>  'title',
    ), $atts) );
    $atts['content'] = $content;

    return include_vc_template('titled_content_box.php', $atts);
}
更新日期:2016年11月7日:

我还建议使用
vc\u map\u get\u attributes
函数,该函数还将所有默认值与您提供的值相结合

正如您在前面的PHP函数中所看到的,我们使用了带有默认值的
title
属性
title
,该属性与
vc\u map
中的默认值不兼容(
(“框标题”、“mytheme”)
),实际上这是一个错误

为避免该错误,请对
$atts
变量使用
vc\u map\u get\u attributes
函数

function titled_content_box_func( $atts, $content, $tag ) {
    $atts = vc_map_get_attributes($tag, $atts);
    $atts['content'] = $content;

    return include_vc_template('titled_content_box.php', $atts);
}

输出内容,但不是100%正确,因为它还混合了HMTL并创建了额外的段落

正确的代码是:

    function titled_content_box_func( $atts, $content = null, $tag ) {
$atts = shortcode_atts( array(
    'title'      =>  'title',
), $atts) );
    $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content

return include_vc_template('titled_content_box.php', $atts);

}

非常感谢,忘记添加$content参数是一个小错误。-我感到惭愧。是的,事实上,在wordpress中,内容属性在回调中转到$content变量是固有的
function titled_content_box_func( $atts, $content, $tag ) {
    $atts = vc_map_get_attributes($tag, $atts);
    $atts['content'] = $content;

    return include_vc_template('titled_content_box.php', $atts);
}
    function titled_content_box_func( $atts, $content = null, $tag ) {
$atts = shortcode_atts( array(
    'title'      =>  'title',
), $atts) );
    $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content

return include_vc_template('titled_content_box.php', $atts);