我映射了以下简码以在 WPBakery 中显示下拉字段:
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Type of container', 'js_composer' ),
'param_name' => 'container_type',
'value' => array(
'Container' => 'container',
'Container fluid (full width)' => 'container-fluid',
),
'std' => 'container',
'description' => esc_html__( 'Select whether you want the content to be contained or full width on the screen.', 'js_composer' ),
)
它正在另一个文件中初始化,其中定义了它的属性和标记:
<?php
/**
* Shortcode attributes
* @var $container_type
*/
class vcRow extends WPBakeryShortCode {
function __construct() {
add_action( 'init', array( $this, 'vc_row_mapping' ) );
add_shortcode( 'vc_row', array( $this, 'vc_row' ) );
}
public function vc_text_mapping() {
vc_map(
array(
'name' => __('row', 'text-domain'),
'base' => 'vc_row',
'description' => __('', 'text-domain'),
'params' => array(
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Type of container', 'js_composer' ),
'param_name' => 'container_type',
'value' => array(
'Container' => 'container',
'Container fluid (full width)' => 'container-fluid',
),
'std' => 'container',
),
);
}
public function vc_row($atts, $content) {
extract(
shortcode_atts(
array(
'container_type' => '',
),
$atts
)
);
if ($container_type == "container-fluid"){
echo "container-fluid";
} else {
echo "container";
}
echo "<p>".$container_type."</p>";
}
}
new vcRow();?>
我的一个字段设置为“container-fluid , but an
echo of
$container_type”显示“容器”(意味着正在执行 else 语句。不确定为什么?