您好我正在使用wordpress网站,如果短代码中的arrtibute设置为“popup =”register“,我现在有一个弹出窗口设置... ...我添加了另一个我要显示的灯箱该属性设置为“popup =”apply“)
我的问题是如何将另一个变量添加到以下函数中..我需要一个if语句吗?我是php的新手,非常感谢任何建议..谢谢!!!!
function oxy_shortcode_button_fancy($atts , $content = '' ) {
// setup options
extract( shortcode_atts( array(
'button_swatch' => 'swatch-coral',
'button_animation' => '',
'size' => 'default',
'xclass' => '',
'link' => '',
'label' => 'My button',
'icon' => '',
'link_open' => '_self',
'popup' => ''
), $atts ) );
$popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
$animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';
}
我想要添加的内容是:
$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';
答案 0 :(得分:1)
尝试使用此代码。希望它可以帮助您
function oxy_shortcode_button_fancy($atts , $content = '' ) {
// setup options
extract( shortcode_atts( array(
'button_swatch' => 'swatch-coral',
'button_animation' => '',
'size' => 'default',
'xclass' => '',
'link' => '',
'label' => 'My button',
'icon' => '',
'link_open' => '_self',
'popup' => ''
), $atts ) );
if('register' == $popup) {
$popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
} else {
$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';
}
$animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';
}