其他语句正在以自定义简码执行

时间:2019-07-10 13:19:40

标签: php html if-statement shortcode wpbakery

我将以下短代码映射为在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`显示“ container”(表示else语句正在执行。不确定为什么吗?

0 个答案:

没有答案